php - Laravel route is redirecting too many times -


i using laravel 5.4 project , scenario if user not have clubs created on login redirect user clubs/create page.

below route page coding

directory structure routes/backend/access.php

route::group([     'prefix'     => 'access',     'as'         => 'access.',     'namespace'  => 'access', ], function () {  route::group([     'middleware' => ['access.routeneedsrole:3', 'first.run'] ], function () {     /*     * clubs management     */     route::group(['namespace' => 'clubs'], function () {      route::get('create', 'clubscontroller@showcreateorganiser')->name('clubs.showcreateorganiser');         /*          * specific club          */         route::group(['prefix' => 'clubs/{club}'], function () {              // access             route::get('login-as', 'clubscontroller@loginas')->name('clubs.login-as');          });          //for when admin logged in user backend         route::get('logout-as', 'clubscontroller@logoutas')->name('clubs.logout-as');           /*clubs crud*/         route::resource('clubs', 'clubscontroller');           //for datatables         route::post('clubs/get', 'clubstablecontroller')->name('clubs.get');          });      }); }); 

below firstrunmiddleware.php code

class firstrunmiddleware {      public function handle($request, closure $next)     {         if (clubs::scope()->count() === 0) {             return redirect()->route('admin.access.clubs.showcreateorganiser');          }          $response = $next($request);          return $response;     } } 

it redirects many times , error message redirected many times.

what doing wrong here??

its because when redirected create page, middleware work again! , check clubs , redirect same page again, , on.

you need make create rout out of firstrunmiddleware scope.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -