Home > Back-end >  Unknown named parameter $store error in Laravel v6
Unknown named parameter $store error in Laravel v6

Time:12-20

I'm working with subdomains in laravel, A vendor comes and opens a store. When a store is created a subdomain is assigned, with this subdomain he/she can access store. It's working fine in local_host as well on staging server (URL: https://spoon-jet.invo.zone) but when I deployed it on production server(URL: https://quickxi-food.invo.zone/) it is giving error,"Unknown named parameter $store". I'm handling subdomain for API's.

Staging Server

When I hit staging server url with subdomain, i.e https://red-rock.spoon-jet.invo.zone/api/login, It gives no error.

Production Server

When I hit staging server url with subdomain, i.e https://red-rock.quickxi-food.invo.zone/api/login, It gives error.

red-rock is a subdomain/store-name

The code on both servers is same.

Api.php

Route::group(['domain' => '{store}.'.config('app.domain'), 'middleware' => ['localization']], function () {

Route::post('login', 'ApiController\AuthController@login');
Route::post('registration', 'ApiController\AuthController@registration');
Route::post('foroget_passworod', 'ApiController\AuthController@forgotPassword');
Route::post('change_passworod', 'ApiController\AuthController@changePassword');
Route::post('verify_verificationcode_forget', 'ApiController\AuthController@verifyVerificationCodeForgetPassword');
Route::post('verify_verificationcode', 'ApiController\AuthController@verify1VerificationCode');
Route::post('device_token', 'ApiController\AuthController@deviceToken');
});

app.domain for staging is: spoon-jet.invo.zone and for production is quickxi-food.invo.zone

Login function:

public function login(Request $request) {

    $validator = Validator::make($request->all(), [
        'mobilenumber' => 'required',
        'password'     => 'required',
        'category'     => 'required',
    ]);

    if ($validator->fails()) {
        return response()->json(["code" => config('constants.VALIDATION_FAILED'), "errors" => $validator->errors()]);
    }

    try {

        $mobileNumber   = $request->mobilenumber;
        $password       = $request->password;
        $category       = $request->category;
        $count          = 0;

        if ($category == "cashier") {
            return response()->jsonResponse(config('constants.ERROR'), trans('api.cashierIsNotAllowedToLogin'), null);
        }

        if (Auth::attempt(['mobilenumber' => $mobileNumber, 'password' => $password, 'category' => $category])) {

            $data['data']   = null;
            $data['count']  = $count;

            $user    = Auth::user();

            if ($user->status == 1) {

                if ($user->isverified == 1) {

                    foreach ($user->tokens as $token) {
                        $token->revoke();
                    }

                    foreach ($user->tokens as $token) {
                        $token->delete();
                    }

                    $token          = $user->createToken('SpoonJet')->accessToken;
                    $user->token    = $token;

                    if ($user->category == "vendor"){
                        $count = vendorNotificationCount($user->id);

                    }elseif($user->category == "user"){
                        $count = userNotificationCount($user->id);

                    }
                    $data['data']   = $user;
                    $data['count']  = $count;
                    return response()->jsonResponse(config('constants.SUCCESS'), trans('api.loginSuccessfully'), $data);

                } else {
                    ////Verification///
                    $data['data']               = $user;
                    $code                       = rand(rand(999, 9999), rand(999, 9999));
                    $msg                        = str_replace(' ', ' ', 'نورتنا ! فضلا أدخل الرمز ') . " " . $code;
                    sendVerificationCode($user->mobilenumber, $msg, $user->id, $code);
                    $data['verificationCode']   = $code;
                    return response()->jsonResponse(config('constants.ACCOUNT_VERIFICATION_NEEDED'), trans('api.pleaseVerifyYourAccount'), $data);
                }
            } else {

                return response()->jsonResponse(config('constants.ADMIN_CONFIRMATION_NEEDED'), trans('api.youNeedAdminConfirmation'), json_decode('{}'));
            }
        } else {
            $count = User::where('mobilenumber', $mobileNumber)->count();
            $data = json_decode('{}');
            if ($count > 0) {
                return response()->jsonResponse(config('constants.ERROR'), trans('api.invalidPassword'), $data);
            } else {
                return response()->jsonResponse(config('constants.ERROR'), trans('api.invalidMobileNumber'), $data);
            }
        }

    } catch (QueryException $exception) {
        return response()->jsonResponse(config('constants.SERVER_ERROR'), $exception->getMessage(), null);
    }catch (Exception $exception) {
        return response()->jsonResponse(config('constants.SERVER_ERROR'), $exception->getMessage(), null);
    }
}

The complete error log:

Symfony\Component\Debug\Exception\FatalThrowableError: Unknown named parameter $store in file /var/www/quickxi-

food/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54

#0 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array()
#1 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#2 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\Routing\ControllerDispatcher->dispatch()
#3 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\Routing\Route->runController()
#4 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): Illuminate\Routing\Route->run()
#5 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#6 /var/www/quickxi-food/app/Http/Middleware/Localization.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#7 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\Http\Middleware\Localization->handle()
#8 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#9 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#10 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#11 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Routing\Middleware\ThrottleRequests->handle()
#12 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#13 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(683): Illuminate\Pipeline\Pipeline->then()
#14 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(658): Illuminate\Routing\Router->runRouteWithinStack()
#15 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): Illuminate\Routing\Router->runRoute()
#16 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(613): Illuminate\Routing\Router->dispatchToRoute()
#17 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(170): Illuminate\Routing\Router->dispatch()
#18 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#19 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#21 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#23 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#24 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#25 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#26 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle()
#27 /var/www/quickxi-food/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#28 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Fideloper\Proxy\TrustProxies->handle()
#29 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#30 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\Pipeline\Pipeline->then()
#31 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#32 /var/www/quickxi-food/public/index.php(55): Illuminate\Foundation\Http\Kernel->handle()
#33 {main}

PS: If you need anything else, please let me know. Thank you in advance.

CodePudding user response:

I found solution, parameters of url/route were not matching with the controller function. See login function:

Before

        public function login(Request $request) {

        $validator = Validator::make($request->all(), [
            'mobilenumber' => 'required',
            'password'     => 'required',
            'category'     => 'required',
        ]);

        if ($validator->fails()) {
            return response()->json(["code" => config('constants.VALIDATION_FAILED'), "errors" => $validator->errors()]);
        }

        try {

            $mobileNumber   = $request->mobilenumber;
            $password       = $request->password;
            $category       = $request->category;
            $count          = 0;

            if ($category == "cashier") {
                return response()->jsonResponse(config('constants.ERROR'), trans('api.cashierIsNotAllowedToLogin'), null);
            }

            if (Auth::attempt(['mobilenumber' => $mobileNumber, 'password' => $password, 'category' => $category])) {

                $data['data']   = null;
                $data['count']  = $count;

                $user    = Auth::user();

                if ($user->status == 1) {

                    if ($user->isverified == 1) {

                        foreach ($user->tokens as $token) {
                            $token->revoke();
                        }

                        foreach ($user->tokens as $token) {
                            $token->delete();
                        }
// dd($user->createToken('SpoonJet'));
                        $token          = $user->createToken('SpoonJet')->accessToken;
                        $user->token    = $token;

                        if ($user->category == "vendor"){
                            $count = vendorNotificationCount($user->id);

                        }elseif($user->category == "user"){
                            $count = userNotificationCount($user->id);

                        }
                        $data['data']   = $user;
                        $data['count']  = $count;
                        return response()->jsonResponse(config('constants.SUCCESS'), trans('api.loginSuccessfully'), $data);

                    } else {
                        ////Verification///
                        $data['data']               = $user;
                        $code                       = rand(rand(999, 9999), rand(999, 9999));
                        $msg                        = str_replace(' ', ' ', 'نورتنا ! فضلا أدخل الرمز ') . " " . $code;
                        sendVerificationCode($user->mobilenumber, $msg, $user->id, $code);
                        $data['verificationCode']   = $code;
                        return response()->jsonResponse(config('constants.ACCOUNT_VERIFICATION_NEEDED'), trans('api.pleaseVerifyYourAccount'), $data);
                    }
                } else {

                    return response()->jsonResponse(config('constants.ADMIN_CONFIRMATION_NEEDED'), trans('api.youNeedAdminConfirmation'), json_decode('{}'));
                }
            } else {
                $count = User::where('mobilenumber', $mobileNumber)->count();
                $data = json_decode('{}');
                if ($count > 0) {
                    return response()->jsonResponse(config('constants.ERROR'), trans('api.invalidPassword'), $data);
                } else {
                    return response()->jsonResponse(config('constants.ERROR'), trans('api.invalidMobileNumber'), $data);
                }
            }

        } catch (QueryException $exception) {
            return response()->jsonResponse(config('constants.SERVER_ERROR'), $exception->getMessage(), null);
        }catch (Exception $exception) {
            return response()->jsonResponse(config('constants.SERVER_ERROR'), $exception->getMessage(), null);
        }
    }

Now

        public function login(Request $request, $store) {

        $validator = Validator::make($request->all(), [
            'mobilenumber' => 'required',
            'password'     => 'required',
            'category'     => 'required',
        ]);

        if ($validator->fails()) {
            return response()->json(["code" => config('constants.VALIDATION_FAILED'), "errors" => $validator->errors()]);
        }

        try {

            $mobileNumber   = $request->mobilenumber;
            $password       = $request->password;
            $category       = $request->category;
            $count          = 0;

            if ($category == "cashier") {
                return response()->jsonResponse(config('constants.ERROR'), trans('api.cashierIsNotAllowedToLogin'), null);
            }

            if (Auth::attempt(['mobilenumber' => $mobileNumber, 'password' => $password, 'category' => $category])) {

                $data['data']   = null;
                $data['count']  = $count;

                $user    = Auth::user();

                if ($user->status == 1) {

                    if ($user->isverified == 1) {

                        foreach ($user->tokens as $token) {
                            $token->revoke();
                        }

                        foreach ($user->tokens as $token) {
                            $token->delete();
                        }
// dd($user->createToken('SpoonJet'));
                        $token          = $user->createToken('SpoonJet')->accessToken;
                        $user->token    = $token;

                        if ($user->category == "vendor"){
                            $count = vendorNotificationCount($user->id);

                        }elseif($user->category == "user"){
                            $count = userNotificationCount($user->id);

                        }
                        $data['data']   = $user;
                        $data['count']  = $count;
                        return response()->jsonResponse(config('constants.SUCCESS'), trans('api.loginSuccessfully'), $data);

                    } else {
                        ////Verification///
                        $data['data']               = $user;
                        $code                       = rand(rand(999, 9999), rand(999, 9999));
                        $msg                        = str_replace(' ', ' ', 'نورتنا ! فضلا أدخل الرمز ') . " " . $code;
                        sendVerificationCode($user->mobilenumber, $msg, $user->id, $code);
                        $data['verificationCode']   = $code;
                        return response()->jsonResponse(config('constants.ACCOUNT_VERIFICATION_NEEDED'), trans('api.pleaseVerifyYourAccount'), $data);
                    }
                } else {

                    return response()->jsonResponse(config('constants.ADMIN_CONFIRMATION_NEEDED'), trans('api.youNeedAdminConfirmation'), json_decode('{}'));
                }
            } else {
                $count = User::where('mobilenumber', $mobileNumber)->count();
                $data = json_decode('{}');
                if ($count > 0) {
                    return response()->jsonResponse(config('constants.ERROR'), trans('api.invalidPassword'), $data);
                } else {
                    return response()->jsonResponse(config('constants.ERROR'), trans('api.invalidMobileNumber'), $data);
                }
            }

        } catch (QueryException $exception) {
            return response()->jsonResponse(config('constants.SERVER_ERROR'), $exception->getMessage(), null);
        }catch (Exception $exception) {
            return response()->jsonResponse(config('constants.SERVER_ERROR'), $exception->getMessage(), null);
        }
    }

You can see that I added $store parameter in login, by adding this problem was solve, I hope this will help future visitors.

  • Related