I want to authenticate the user whose credential is stored in using GuzzleHTTP GET method. I already created register API.
http://restapitest.local/api/v1/user/register :
public function register(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'password' => 'required|min:5'
]);
$name = $request->input('name');
$email = $request->input('email');
$password = $request->input('password');
$user = new User([
'name' => $name,
'email' => $email,
'password' => bcrypt($password)
]);
if($user->save()){
$user->signin = [
'href' => 'api/v1/user/singin',
'method' => 'POST',
'params' => 'email, password'
];
$response = [
'msg' => 'User created',
'user' => $user
];
return response()->json($response, 201);
}
$response = [
'msg' => 'Error occured'
];
return response()->json($response, 404);
}
What I tried is http://restapitest.local/api/v1/user/singin:
public function signin()
{
$client = new \GuzzleHttp\Client();
$response = $client->request(
'GET', /*instead of POST, you can use GET, PUT, DELETE, etc*/
'http://restapitest.local/api/v1/user/singin',
[
'auth' => ['email','password'] /*if you don't need to use a password, just leave it null*/
]
);
return response()->json($response->getBody());
}
Please, can someone post with a good explanation?