jeudi 25 mai 2017

How to call controller function from handler?

I have Handler.php (app/Exceptions/Handler.php)

I want to call controller method from render method of Handler.php.

Here is the render method and what I have tried,

public function render($request, Exception $e)
{   
    $common_vars                    = app()->call(\App\Http\Controllers\TestController::class."@".getMenusAndConfigs('users'));
    if ($this->isHttpException($e)) {
        switch ($e->getStatusCode()) {

            // not authorized
            case '403':
                return \Response::view('errors.403', array(), 403);
                break;

            // not found
            case '404':
                return \Response::view('errors.404', $common_vars, 404);
                break;

            // internal error
            case '500':
                return \Response::view('errors.500', array(), 500);
                break;

            default:
                return $this->renderHttpException($e);
                break;
        }
    } else {
        return parent::render($request, $e);
    }
    // return parent::render($request, $e);
}

I can get $common_vars by calling test controller in other controllers, but I want this in Handler.php

How can we achieve this ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qRXdxr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire