我試圖在我的編輯請求中授權失敗時在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