Laravel v6 中的未知命名参数 $store 错误

Unknown named parameter $store error in Laravel v6

我正在 laravel 中处理子域,一位供应商来了并开了一家商店。创建商店时会分配一个子域,使用此子域 he/she 可以访问商店。 它在 local_host 以及登台服务器 (URL: https://spoon-jet.invo.zone) but when I deployed it on production server(URL: https://quickxi-food.invo.zone/) 中工作正常,但出现错误,“未知命名参数 $store”。我正在处理 API 的子域。

登台服务器

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

生产服务器

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

两台服务器上的代码相同。

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

登录函数:

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(' ', '%20', 'نورتنا ! فضلا أدخل الرمز ') . "%20" . $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);
    }
}

完整的错误日志:

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:如果您还需要什么,请告诉我。提前谢谢你。

我找到了解决方案,url/route的参数与控制器功能不匹配。 查看登录功能:

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(' ', '%20', 'نورتنا ! فضلا أدخل الرمز ') . "%20" . $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(' ', '%20', 'نورتنا ! فضلا أدخل الرمز ') . "%20" . $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);
        }
    }

您可以看到我在登录时添加了$store参数,通过添加这个问题就解决了,希望对以后的访问者有所帮助。