2020-06-23 04:42:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Response;
|
2020-08-27 08:59:19 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2020-06-23 04:42:43 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
use Jenssegers\Agent\Facades\Agent;
|
|
|
|
|
|
|
|
class DetectorServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2020-06-24 06:21:00 +00:00
|
|
|
Response::macro("detect", function ($view, $args = []) {
|
2020-06-23 04:42:43 +00:00
|
|
|
if(Agent::isMobile()) {
|
|
|
|
return view(config("detector.mobilePath") . "." . $view, $args);
|
2020-08-27 08:59:19 +00:00
|
|
|
} else if(Auth()->user() !== null){
|
|
|
|
if(Auth()->user()->can('admin.panel.show') == true)
|
|
|
|
return view(config("detector.defaultPath") . "." . $view, $args);
|
2020-06-23 04:42:43 +00:00
|
|
|
}
|
2020-08-27 10:46:07 +00:00
|
|
|
if($view == "users.login" || $view == "users.logout")
|
|
|
|
return view(config("detector.mobilePath") . "." . $view, $args);
|
2020-08-27 08:59:19 +00:00
|
|
|
|
2020-08-27 09:12:43 +00:00
|
|
|
return view("errors.403", $args);
|
2020-06-23 04:42:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|