Redirecting to home route after sending get request to nested resource controller

Posted 2 years ago by anonymox

I'm trying to reach to my nested resource controller by passing this url in postman with get method :

    http://peoject.local/api/admin/users/4/seats

my api.php file is like :

      Route::group(['prefix' => 'admin'], function () {
            Route::resource('users', 'Admin\UsersController', ['except' => ['store', 'create', 'edit']]);
    
            Route::resource('users.seats', 'Admin\ASeatController', ['only' => ['index', 'show', 'update', 'destroy']]);
    
            Route::resource('banners', 'Admin\BannersController', ['except' => ['edit', 'create']]);
        });

I want to get the user id in ASeatController :

  /**
         * Display a listing of the resource.
         *
         * @param $userId
         * @return \Illuminate\Http\Response
         */
        public function index($userId)
        {

            try {
                $statusCode = 200;

                $domains = Seat::where('user_id', '=', $userId)->first();
    
            } catch (\Exception $e) {
                $statusCode = 400;
            } finally {
                $response = \Response::json($domains, $statusCode);
                return $response;
            }
        }

But when I test it I redirect to /home, and I don't know why. I followed official laravel docs to do this.

Any Idea how to fix this ?

FYI : I'm using laravel 5.3

Please sign in or create an account to participate in this conversation.