我正在laravel中处理子域,一个供应商来开了一家商店。当创建一个存储时,会分配一个子域,通过这个子域,他/她可以访问存储。它在local_host中运行良好,在临时服务器上运行良好(URL:https://spoon-jet.invo.zone(,但当我在生产服务器上部署它时(URL:https://quickxi-food.invo.zone/(它给出错误;未知的命名参数"$store";。我正在处理API的子域。
暂存服务器
当我点击带有子域的暂存服务器url时,即https://red-rock.spoon-jet.invo.zone/api/login,它不会出错。
生产服务器
当我点击带有子域的暂存服务器url时,即https://red-rock.quickxi-food.invo.zone/api/login,它给出了错误。
red-rock is a subdomain/store-name
两台服务器上的代码相同。
Api.php
Route::group(['domain' => '{store}.'.config('app.domain'), 'middleware' => ['localization']], function () {
Route::post('login', 'ApiControllerAuthController@login');
Route::post('registration', 'ApiControllerAuthController@registration');
Route::post('foroget_passworod', 'ApiControllerAuthController@forgotPassword');
Route::post('change_passworod', 'ApiControllerAuthController@changePassword');
Route::post('verify_verificationcode_forget', 'ApiControllerAuthController@verifyVerificationCodeForgetPassword');
Route::post('verify_verificationcode', 'ApiControllerAuthController@verify1VerificationCode');
Route::post('device_token', 'ApiControllerAuthController@deviceToken');
});
应用程序域用于分期是:勺式喷射。invo.zone,用于<strong]生产>的是快餐。invo.地域
登录功能:
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);
}
}
完整的错误日志:
SymfonyComponentDebugExceptionFatalThrowableError: 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): IlluminateRoutingController->callAction()
#2 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): IlluminateRoutingControllerDispatcher->dispatch()
#3 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): IlluminateRoutingRoute->runController()
#4 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): IlluminateRoutingRoute->run()
#5 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): IlluminateRoutingRouter->IlluminateRouting{closure}()
#6 /var/www/quickxi-food/app/Http/Middleware/Localization.php(25): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#7 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): AppHttpMiddlewareLocalization->handle()
#8 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#9 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): IlluminateRoutingMiddlewareSubstituteBindings->handle()
#10 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(59): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#11 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): IlluminateRoutingMiddlewareThrottleRequests->handle()
#12 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#13 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(683): IlluminatePipelinePipeline->then()
#14 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(658): IlluminateRoutingRouter->runRouteWithinStack()
#15 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): IlluminateRoutingRouter->runRoute()
#16 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Routing/Router.php(613): IlluminateRoutingRouter->dispatchToRoute()
#17 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(170): IlluminateRoutingRouter->dispatch()
#18 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): IlluminateFoundationHttpKernel->IlluminateFoundationHttp{closure}()
#19 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#20 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): IlluminateFoundationHttpMiddlewareTransformsRequest->handle()
#21 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#22 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): IlluminateFoundationHttpMiddlewareTransformsRequest->handle()
#23 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#24 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): IlluminateFoundationHttpMiddlewareValidatePostSize->handle()
#25 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#26 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): IlluminateFoundationHttpMiddlewareCheckForMaintenanceMode->handle()
#27 /var/www/quickxi-food/vendor/fideloper/proxy/src/TrustProxies.php(57): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#28 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): FideloperProxyTrustProxies->handle()
#29 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): IlluminatePipelinePipeline->IlluminatePipeline{closure}()
#30 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): IlluminatePipelinePipeline->then()
#31 /var/www/quickxi-food/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): IlluminateFoundationHttpKernel->sendRequestThroughRouter()
#32 /var/www/quickxi-food/public/index.php(55): IlluminateFoundationHttpKernel->handle()
#33 {main}
PS:如果您还需要什么,请告诉我。提前谢谢。
我找到了解决方案,url/route的参数与控制器功能不匹配。请参阅登录功能:
之前
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);
}
}
现在
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参数,通过添加这个问题已经解决了,我希望这将对未来的访问者有所帮助。