Answer the question
In order to leave comments, you need to log in
Why doesn't the method declared in the constructor work?
Why does the gate facade's denies method work like this:
public function __construct()
{
$this->middleware('auth');
}
public function index(){
if(Gate::denies('VIEW_ADMIN')){
return redirect('myprofile');
}
$array = array(
'title'=>'Админ панель. Главная.',
'user'=>$this->getCurUser(),
);
if(view()->exists('pages.admin.index.index-content')){
return view('pages.admin.index.index-content', $array);
}
abort(404);
}
public function __construct()
{
$this->middleware('auth');
if(Gate::denies('VIEW_ADMIN')){
return redirect('myprofile');
}
}
public function index(){
$array = array(
'title'=>'Админ панель. Главная.',
'user'=>$this->getCurUser(),
);
if(view()->exists('pages.admin.index.index-content')){
return view('pages.admin.index.index-content', $array);
}
abort(404);
}
Answer the question
In order to leave comments, you need to log in
you need to wrap the code in middleware
public function __construct()
{
$this->middleware('auth');
$this->middleware(function ($request, $next) {
if(Gate::denies('VIEW_ADMIN')){
return redirect('myprofile');
}
return $next($request);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question