This commit is contained in:
2020-08-27 15:30:26 +02:00
6 changed files with 99 additions and 8 deletions
+8 -4
View File
@@ -3,9 +3,7 @@
namespace App\Helpers;
use Illuminate\Support\Facades\Auth;
use Jenssegers\Agent\Agent;
class Detector
@@ -16,7 +14,13 @@ class Detector
if($agent->isMobile()) {
return view(config("detector.mobilePath") . "." . $viewName, $args);
} else if(Auth()->user() !== null) {
if (Auth()->user()->can('admin.panel.show') == true)
return view(config("detector.defaultPath") . "." . $viewName, $args);
}
return view(config("detector.defaultPath") . "." . $viewName, $args);
if($viewName == "users.login" || $viewName == "users.logout")
return view(config("detector.mobilePath") . "." . $viewName, $args);
return view("errors.403", $args);
}
}
@@ -19,16 +19,16 @@ class RootController extends Controller
if(auth()->user()->can('admin.panel.show')) {
if(Response::detect("root.index")->name() == "admin.root.index")
return Response::detect("root.index");
return view("admin.root.index");
else {
$news = News::query()->orderBy('id', 'desc')->paginate($perPage);
return Response::detect("root.index", ["news" => $news]);
return view("app.root.index", ["news" => $news]);
}
}
else {
$news = News::query()->orderBy('id', 'desc')->paginate($perPage, ['*'], "page");
return view('app.root.index', ["news" => $news]);
return Response::detect('root.index', ["news" => $news]);
}
}
}
@@ -3,6 +3,7 @@
namespace App\Providers;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;
use Jenssegers\Agent\Facades\Agent;
@@ -28,8 +29,14 @@ class DetectorServiceProvider extends ServiceProvider
Response::macro("detect", function ($view, $args = []) {
if(Agent::isMobile()) {
return view(config("detector.mobilePath") . "." . $view, $args);
} else if(Auth()->user() !== null){
if(Auth()->user()->can('admin.panel.show') == true)
return view(config("detector.defaultPath") . "." . $view, $args);
}
return view(config("detector.defaultPath") . "." . $view, $args);
if($view == "users.login" || $view == "users.logout")
return view(config("detector.mobilePath") . "." . $view, $args);
return view("errors.403", $args);
});
}
}