Laravel 4: Route to the controller when an error occurs

I have a problem with laravel 4. I want to handle errors that have occurred, such as 404 Not Foundor any other errors. But I want to call the controller when such errors occur. I tried this:

App::missing(function($exception)
{
    return Response::view('errors.404', array('error'=>$exception), 404);
});

But actually over the code is not my goal, I want something like this:

//I know this code doesn't work, I've just wanted to show the claim
App::missing('HomeController@error');
App::error('HomeController@error');
// or ...

Is there a way to handle errors in calling a specific controller method?

+4
source share
2 answers

No, you cannot use App::missing('Controller@method')directly, because the method missingcalls the method error, namely:

public function error(Closure $callback)
{
    $this['exception']->error($callback);
}

, controllermethod . . , , , .

/ , ( , ) , ?

Update:

App::missing(function($e){
    // Use the model here you want
    $var = 'SomeValue' from model
    return Response::view('errors.404', array('error'=> $e, 'another' => $var));
});
+3

, .

App::missing(function($exception)
{
    return App::make('HomeController')->error($exception);
});
+5

Source: https://habr.com/ru/post/1535227/


All Articles