Answer the question
In order to leave comments, you need to log in
How to enable debug laravel for admins only?
I want to disable debug in the browser for all users except the admin, I did everything according to this instruction , but something does not work.
Fragment config/app.php (I have disabled Debug Mode):
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => false,
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class OnEnter
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::user()->moderated == '8') //Так у меня идет проверка админа
{
Config::set('app.debug', true);
}
}
}
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'enter' => \App\Http\Middleware\OnEnter::class,
];
Answer the question
In order to leave comments, you need to log in
Throw it not in the routeMiddleware (everything in the routeMiddleware is called only by hand from the route or controller)
As I understand it, you need the $middleware array which is higher, then the mildware is executed on EVERY request.
But I think it's better to throw it in the web group
protected $middlewareGroups = [
'web' => [ вот сюда
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question