@rodrigo.pedra my head hurts figuring out lately why is that im still not getting error hahahaha
@rodrigo.pedra should i edit the RouteServiceProvider.php to redirect when they try to access a non existing username? or is it other file i should edit?
I handle it on my app/Exceptions/Handler class render() method like this:
public function render( $request, Exception $e )
{
if ( $e instanceof ModelNotFoundException )
{
return redirect()->back()->withInput()->withErrors( 'The resource does not exist' );
}
return parent::render( $request, $e );
}
I actually check for many more exceptions, it would very long to paste here, but this exception is the one raised by ->firstOrFail() when a model is not found.
I prefer to handle it here because of the separation of concerns principle, which says one class should be responsible for one task only. So handling exception belongs to this class.
see the laracasts collections about SOLID principles: [ https://laracasts.com/collections/solid-principles ].
thanks bro will watch that laracasts video, again thanks a lot what a day hahaha
You can also customize the key name for the route model binding by adding this to your user model :
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
{
return 'username';
}
Référence : https://laravel.com/docs/5.4/routing#route-model-binding
Please or to participate in this conversation.