lundi 10 juin 2019

Use variable in whole controller

I have an if statement based on entrust roles package, and i want to use the outcome to prefix my return views in laravel. What options do i have?

What i have now:

public function __construct() {        
    if (Auth::user()->hasRole('administrator')) {
        $route = 'admin';
    } else if (Auth::user()->hasRole('company')) {
        $route = 'company';
    } else if (Auth::user()->hasRole('schoolowner')) {
        $route = 'school';
    }
}

public function index()
{
    return view($route.'.person.index', compact('user'))->with('status', 'No school');
}

How can i use the if statement variable inside return view function in a laravel way? Or even use the outcome on all controllers

Should i use middleware? Or just the php way

Or view share in provider?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire