朋友我是laravel的新手如何在laravel中提供所需的响应代码?对我来说,它返回402作为状态代码。请给出如何提供响应代码的建议
public function register(Request $request){
$this->validate($request, [
'name' => 'required',
'email' => 'required|email|unique:users,email',
'password' => 'required|min:6|confirmed'
]);
$user = User::create([
'name' => request('name'),
'email' => request('email'),
'password' => bcrypt(request('password'))
]);
$params = [
'grant_type' => 'password',
'client_id' => $this->client->id,
'client_secret' => $this->client->secret,
'username' => request('email'),
'password' => request('password'),
'scope' => '*'
];
$request->request->add($params);
$statusCode = 200;
$proxy = Request::create('oauth/token','POST');
$data = Request::dispatch($proxy);
return response()->json($proxy, $statusCode);
//return Route::dispatch($proxy);
}</code><pre>
答案 0 :(得分:0)
在我看来,您只是返回生成令牌的请求,返回响应并能够更改将Request::dispatch
调用的结果放入变量所需的状态代码,然后使用状态代码返回正确的响应。
这是您使用特定状态代码返回响应的方式;您将如何处理更改状态代码完全取决于您:
$statusCode = 200; //it can be any valid HTTP STATUS CODE
$data = Request::dispatch($proxy);
return response()->json($data , $statusCode);