Roo Roo - 5 months ago 39
PHP Question

Laravel ModelNotFound exception handling with namesapces

I have this problem where laravel ModelNotFound exeption handler catches all exceptions not only releated to eloquent.

I have added to

this code:

// this is default code
App::error(function(Exception $exception, $code)
// added code
App::error(function(ModelNotFoundException $exception)
//do something, in my case redirect to 404 or whaterver

Controller has this partial code:

namespace CompanyName\Admin;

class PromosController extends CompanyNameAdminController {

public function show($id) {
$promo = Promo::findOrFail($id);

Now if I try to pass id that dont exist I will recieve white page, code in app error does not execute. Other problem is that this App:error catches all Exeptions, like not found conrollers etc, basicly every exeption.

What I am doing wrong? I got this idea from Laracasts Exeptions handling episode, but somehow Im missing something. Because I get no feedback form Laravel about problem I am stuck. I suspect that namespaces has something to do with it but I am not sure..

At last I found some feedback in console:
500 Internal Server Error
Reload the page to get source for:


ModelNotFoundException is not in that namespace, so it is not being found. Specify the qualified name:

App::error(function(Illuminate\Database\Eloquent\ModelNotFoundException $exception)
    //do something, in my case redirect to 404 or whaterver