Search code examples
phpapachelaravel-5routesmiddleware

unique route request needs multiple controller laravel



I am working on one laravel project. I am new to laravel. I have few roles(editor,user,admin) in the system. We don't need multi auth system. I don't need multi auth for different roles and create prefix based routes accordingly.
e.g

www.sitename.com/admin/editprofile, www.sitename.com/editor/editprofile 

Let's say if all above mentioned roles request for

www.sitename.com/editprofile

then I want to call individual controller based on role, so I can handle request properly and my code remain clean. I don't want to do all the things in single controller.

When user/role updates profile, different roles have different input fields so it's better to distribute request to individual controller.

Currently, I am using below package for roles and permission which is nice still. https://github.com/spatie/laravel-permission

Environments:

Laravel Version: 5.3
DATABASE: Mysql
Server: Apache

Please help me on this.


Solution

  • You should be able to 'listen' on 1 controller method and then redirect to others based on the input. At least with 5.3:

    https://laravel.com/docs/5.3/redirects#redirecting-controller-actions