当我开始使用 Laravel 时,这应该很简单:当我的路由模型绑定找不到给定的 ID 时,如何定义要呈现的自定义视图?
这是我的路线:
Route::get('/empresa/edit/{empresa}', 'EmpresaController@edit');
这是我的控制器的方法:
public function edit(Empresa $empresa)
{
if ((!isset($empresa)) || ($empresa == null)):
//I get that this won't work...
return 'Empresa não encontrada';
endif;
return view('Empresa.dadosEmpresa')->with('empresa', $empresa)->with('action', URL::route('empresa_update', ['id', $empresa->id]))->with('method', 'PATCH');
}
这是我使用错误处理程序的“尝试”:
public function render($request, Exception $exception)
{
if ($e instanceof ModelNotFoundException)
{
//this is just giving me a completely blank response page
return 'Empresa não encontrada';
}
return parent::render($request, $exception);
}
这真的是怎么做到的?