我试图在我的编辑请求中授权失败时在laravel中显示自定义403文件。如果授权失败,Laravel自定义错误页面
我试过forbiddenResponse()
但事实证明它已被淘汰。
然后我尝试了failedauthorization()
,但这并没有重定向,并允许我编辑。
这里是我的请求文件
public function authorize()
{
$job_posting_id = $this->route('id');
$job_posting = Job_postings::where('id', $job_posting_id)->where('user_id', user()->id)->exists();
if($job_posting){
return true;
}
return false;
}
public function failedAuthorization()
{
return redirect('errors.dashboard.parent.403');
}
我有一个文件夹叫错误,里边有我有仪表盘的文件夹和家长在错误文件的位置。
如果授权失败,我该如何重定向到该页面?
'返回查看( 'errors.dashboard.parent.403')'? –
我也尝试过,但它只是传递它并去编辑。 – raqulka
你需要创建一个异常,并在Exceptions/Handler.php文件的报告方法中做'if($ e实例YOUREXCEPTION){//这里返回你的视图}' – Vikash