当通过 Postman 端口发送到数据库的数据崩溃并且该端口在 laravel 中无法进一步工作时
When data sent to db via Postman port get crashed and that port dosent work futher in laravel
我正在尝试 laravel 护照进行身份验证。在阅读了它的文档后,我在代码行下方进行了编码,并尝试通过邮递员传递图像中的数据:
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use GuzzleHttp\Client;
class AuthController extends Controller
{
public function register(Request $request){
$validationData = $request->validate([
'email' => 'required',
'name' => 'required',
'password' => 'required'
]);
$user = User::firstOrNew(['email' => '$request->email']);
$user->name = $request->name;
$user->email = $request->email;
$user->password = md5($request->password);
$user->save();
$http = new Client;
$response = $http->post(url('oauth/token'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => '2',
'client_secret' => 'WXXWDxYHfIPu5fbkSSTCnw56Gk0VJ271KDEd9NKr',
'email' => $request->email,
'password' => $request->password,
'scope' =>'',
],
]);
return response (['data' => json_decode((string) $response->getBody(), true)]);
}
public function login(){
}
}
当我检查数据库数据时,它已发布到 table,但直到我停止请求才停止。然后,当我尝试重新发送请求时,它会抛出错误消息说 email almost exist 。我知道没问题。但是8016端口没有反应了。谁能告诉我这里出了什么问题,谢谢。
请允许我开始:
关于邮递员..
您正在使用 HTTP POST 而不是使用正文,而是在 url 上发送参数。为什么使用参数而不是在正文中发送它们? (在 guzzle 代码中,您在正文中发送内容)。
去除方法中的验证,如果您要验证表单,如果您在别处创建一组验证,则可以更好地组织代码。
https://laravel.com/docs/5.7/validation#creating-form-requests
请停止使用 md5,您在 Laravel 中有一个密钥,相应地散列它。
\Hash::make($request->password); instead of $user->password = md5($request->password);
如果您对项目的请求将向外部发出请求 url,您需要考虑如果请求由于某种原因(500、404、403)而失败时可能发生的情况。如果您要请求自己的路线,为什么要使用 guzzle?您可以在内部调用路由(即使没有必要,如果您需要自己代码中的功能,您可以调用它)
"When I check the database data has been posted into the table but the request sending will not be stopped utill i stop."
很可能是因为您正在发出 HTTP 请求,正如我上面所说,只需在内部调用您自己的代码函数并取出 guzzle。
你已经查过那里的数据库了吗?
可能有一个记录 $request->email。不能用单引号写变量
这么写
$user = User::firstOrNew(['email' => $request->email]);
或
$user = User::firstOrNew(['email' => "$request->email"]);
我正在尝试 laravel 护照进行身份验证。在阅读了它的文档后,我在代码行下方进行了编码,并尝试通过邮递员传递图像中的数据:
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use GuzzleHttp\Client;
class AuthController extends Controller
{
public function register(Request $request){
$validationData = $request->validate([
'email' => 'required',
'name' => 'required',
'password' => 'required'
]);
$user = User::firstOrNew(['email' => '$request->email']);
$user->name = $request->name;
$user->email = $request->email;
$user->password = md5($request->password);
$user->save();
$http = new Client;
$response = $http->post(url('oauth/token'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => '2',
'client_secret' => 'WXXWDxYHfIPu5fbkSSTCnw56Gk0VJ271KDEd9NKr',
'email' => $request->email,
'password' => $request->password,
'scope' =>'',
],
]);
return response (['data' => json_decode((string) $response->getBody(), true)]);
}
public function login(){
}
}
当我检查数据库数据时,它已发布到 table,但直到我停止请求才停止。然后,当我尝试重新发送请求时,它会抛出错误消息说 email almost exist 。我知道没问题。但是8016端口没有反应了。谁能告诉我这里出了什么问题,谢谢。
请允许我开始:
关于邮递员.. 您正在使用 HTTP POST 而不是使用正文,而是在 url 上发送参数。为什么使用参数而不是在正文中发送它们? (在 guzzle 代码中,您在正文中发送内容)。
去除方法中的验证,如果您要验证表单,如果您在别处创建一组验证,则可以更好地组织代码。
https://laravel.com/docs/5.7/validation#creating-form-requests
请停止使用 md5,您在 Laravel 中有一个密钥,相应地散列它。
\Hash::make($request->password); instead of $user->password = md5($request->password);
如果您对项目的请求将向外部发出请求 url,您需要考虑如果请求由于某种原因(500、404、403)而失败时可能发生的情况。如果您要请求自己的路线,为什么要使用 guzzle?您可以在内部调用路由(即使没有必要,如果您需要自己代码中的功能,您可以调用它)
"When I check the database data has been posted into the table but the request sending will not be stopped utill i stop."
很可能是因为您正在发出 HTTP 请求,正如我上面所说,只需在内部调用您自己的代码函数并取出 guzzle。
你已经查过那里的数据库了吗? 可能有一个记录 $request->email。不能用单引号写变量 这么写
$user = User::firstOrNew(['email' => $request->email]);
或
$user = User::firstOrNew(['email' => "$request->email"]);