I want to create Laravel REST API for user registration and login. I created POST method for registration. Now I want to use GET method for login using GuzzleHttp. How can I do that? My routes:
Route::group(['middleware' => 'api'], function() {
Route::group(['prefix' => 'v1'], function () {
Route::post('/register', 'Api\V1\AuthController@register')->name('user.register');
Route::get('/signin', 'Api\V1\AuthController@signin')->name('user.signin');
});
});
And this is my controller:
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\JWTAuth;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
class AuthController extends Controller
{
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()){
$response = [
'msg' => 'User created',
'user' => $user
];
return response()->json($response, 201);
}
$response = [
'msg' => 'Error occured'
];
return response()->json($response, 404);
}
public function signin(Request $request)
{
$client = new GuzzleHttp\Client();
$this->validate($request, [
'email' => 'required|email',
'password' => 'required'
]);
}
}
Anyone did something like this. Thanks in advance.
Access the
signin
routes like thishttp://your.domain/signin?email=cool@email.com&password=fooandbar
To access the
email
andpassword
parameteruse
$request->email
and$request->password