当我发送 POST 请求时,Laravel 在控制器中作为 Get 请求返回。
我的网址,
http://localhost/walls/app/api/public/api/auth/signup
我的路线,
Route::group(['prefix' => 'auth'], function () {
Route::post('signup', 'AuthenticateController@signup');
});
验证控制器,
public function signup(SignupRequest $request) {
return $request;
}
回应是,
GET
{
"user_type": "1",
"name": "shihab",
"email": "[email protected]",
"password": "123456",
"access_token": "",
"refresh_token": "",
"expiry_date": ""
}
它工作正常,但有时会显示这种错误。请问是什么原因,如何解决?
我曾经遇到过这样的问题。问题出在路线上 应该是这样的:
Route::post('/signup', 'AuthenticateController@signup');
并且您必须确保请求以 POST 方式发送(观察网络)。
抱歉我无法添加评论
当我使用 php artisan 运行我的应用程序时,我遇到同样的问题:服务工作正常,但在生产服务器(带有 nginx 服务器的 aws elastic beanstalk)中,我的应用程序抛出此错误。
我的观点如下:
<form action="{{ route('sign-up.company.store') }}" method="POST">@csrf
我的路线定义:
Route::post('company/signup/store',[RegistrationController::class, 'signUpCompanyStore'])->name('sign-up.company.store');
我的控制器方法具有以下操作:
//To be noted for security reasons i've removed some code from my controller method
public function signUpCompanyStore(Request $request){
$request->validate([
'first_name' => ['required','max:60'],
'last_name' => ['required','max:60'],
'email' => ['required','email','unique:users,email']]);
$role = CompanyRole::where('name', 'Company')->first();
// new user registation
$company_name = $request->first_name.$number;
$noWhiteSpaceString = str_replace(' ', '',$company_name);
$smailletter = Str::lower($noWhiteSpaceString);
$address = UserAddress::where('user_id',1)->first();
$data = User::create([
'role_id' => 0,
'password' => Hash::make($request->password),
'email_verified_at'=> $address->is_verified == 2 ? now() : null,
'status'=>1
]);
Mail::to($data->email)->send( new SendEmailVerification($data));
$package = Package::where('slug','free')->first();
$order = CompanyOrder::create([
'order_id' => id_generate(1,8),
'status' => 1,
]);
Invoice::create([
'user_id' => $order->user_id,
'status' => $order->status,
]);
if ($address->is_verified == 1) {
if ($address->cron_job_mail == 1) {
dispatch(new SendEmailVerificationJob($data))->delay(now()->addSeconds(5));
} else {
$email = new SendEmailVerification($data);
Mail::to($data->email)->send($email);
}
}
Auth::login($data,true);
return redirect()->route('login')->with('success','Registration Successfuly !');
}