Support the ongoing development of Laravel.io →
posted 7 years ago
IOC

My route is

         Route::resource('product', 'Product\ProductController');

My ProductController

         public function index(){
	          $role = Auth::User()->roles->first()->name;
	            $this->roleName = str_replace(' ', '', $role);
	             return app('App\Http\Controllers\Product'. '\\'. $this->roleName. 'ProductController')->index();

     }

Everything works fine it triggers AdminProductController or AreaManagerProductController and in the service providers

 $this->app->when(AdminController::class)
          ->needs(UserInterface::class)
          ->give(AdminRepository::class);

    $this->app->when(AreaManagerProductController::class)
      ->needs(UserInterface::class)
      ->give(AreaManagerRepository::class);

The problem is... it doesn't trigger $this->middleware('sample') both controllers. Is there a better way to do this? Thanks.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

bobbygerez bobbygerez Joined 27 May 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.