Friday, March 3, 2017

Catch ModelNotFound from substitueBindings

I am using the CORS plugin and need to add custom headers inside the ExceptionHandler render function.

But a route like

Route::get('models/{model}', 'ModelController@index');

will never fire a ModelNotFoundException or another exception.

Docuemantation (https://laravel.com/docs/5.4/routing#explicit-binding):

If a matching model instance is not found in the database, a 404 HTTP response will be automatically generated.

So how it is possible to jump into the error function by still using substituteBinding?



via mimo

Advertisement