login api in laravel code example
Example 1: laravel token authentication
Schema::table('users', function ($table) {
$table->string('api_token', 80)->after('password')
->unique()
->nullable()
->default(null);
});
$token = Str::random(60);
$user = User::find(1);
$user->api_token = hash('sha256', $token);
$user->save();
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
axios.get('http://example.com/api/user',
{
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer '+ 'user-api-token'
}
}
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
Example 2: laravel passport
php artisan passport:install
Example 3: login with laravel
html { height: 100%; }
body {
min-height:100%;
position:relative;
padding-bottom:[footer-height]
}
.footer {
position: absolute;
left: 0 ; right: 0; bottom: 0;
height:[footer-height]
}