lundi 28 août 2017

Laravel 5.4 - choose route based on role

I have following code:

 Route::group(['middleware' => ['auth']], function () {

        dd($user);
        Route::get('/', 'SiteController@index');
    });

The $user is created in the AppServiceProvider, but it is not accessible in the Route:

public function boot()
    {
        view()->composer('layouts.main', function($view){

            $employees     = \App\Bamboo::getEmployees();
            $employeeIndex = \App\Bamboo::getEmployeeIndex(auth()->user()->email, $employees);

            $view->with('employees', $employees);
            $view->with('user', $employees['employees'][$employeeIndex]);
        });
    }

Is there a why for me to choose which function will be called in the SiteController based on the role (this is contained in the $user)?

I want to do something like this:

$method = $user->role === 'dev' ? 'index' : 'admin';

Route::get('/', "SiteController@{$method}");

Is this p



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire