Dynamic load routes file based on Middleware user

Im trying to make a dynamic routing based on route file. example if user1 login, routes/api1.php will load and if user2 login, routes/api2.php will load. is it possible?

sample pseudocode:

if user == user1
    then base_path("routes/api1.php") load
if user == user2
    then base_path("routes/api2.php") load

inside api1.php will be

Route::namespace('UserPath1')->group(function() {
   Route::get('tester', 'ApiIndexController@index');
});

inside api2.php will be

Route::namespace('UserPath2')->group(function() {
   Route::get('tester', 'ApiIndexController@index');
});

Below is currently i do.

enter image description here

1 answer

  • answered 2019-10-16 15:31 ZeroOne

    After try and error for hours, its working now. The mistake is where i didnt specify the current auth attribute which is api_vendor.

    if the current user have token, then the specific route loaded. If no token attach, it will fall into black hole route :D

    enter image description here