我的路线/api.php具有以下路线:
Route::post('/signup' , 'UserApiController@signup');
Route::post('/logout' , 'UserApiController@logout');
Route::post('/verify' , 'UserApiController@verify');
但是当我试图像这样从Postman访问时,它显示找不到对象:
localhost/my_webiste/api/signup
此处是userapicontroller的注册功能:
public function signup(Request $request)
{
$this->validate($request, [
'social_unique_id' => ['required_if:login_by,facebook,google','unique:users'],
'device_type' => 'required|in:android,ios',
'device_token' => 'required',
'device_id' => 'required',
'login_by' => 'required|in:manual,facebook,google',
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'mobile' => 'required',
'password' => 'required|min:6',
]);
try{
$User = $request->all();
$User['payment_mode'] = 'CASH';
$User['password'] = bcrypt($request->password);
$User = User::create($User);
return $User;
} catch (Exception $e) {
return response()->json(['error' => trans('api.something_went_wrong')], 500);
}
}
此处是localhost/mywebsite/api/signup
的发布请求的邮递员输出:
<title>Object not found!</title>
<link rev="made" href="mailto:postmaster@localhost" />
<h1>Object not found!</h1>
The requested URL was not found on this server.
If you entered the URL manually please check your
spelling and try again.
答案 0 :(得分:2)
确保在邮递员中添加标题accept
= application/json
。
答案 1 :(得分:0)
您的代码正确。似乎您在url上缺少公开信息
localhost/my_webiste/public/api/signup