1. Go to this page and download the library: Download miladrahimi/larajwt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
miladrahimi / larajwt example snippets
php artisan vendor:publish --tag=larajwt-config
$credential = [
'email' => $request->input('email'),
'password' => $request->input('password'),
];
if(Auth::guard('api')->attempt($credential)) {
$user = Auth::guard('api')->user();
$jwt = JwtAuth::generateToken($user);
// Return successfull sign in response with the generated jwt.
} else {
// Return response for failed attempt...
}
Route::group(['middleware' => 'auth:api'], function () {
// Routes...
});
class AuthServiceProvider extends ServiceProvider
{
// ...
public function boot()
{
// ...
$jwtAuth = $this->app->make(JwtAuthInterface::class);
// Check if user is active or not
$jwtAuth->registerFilter(function (User $user) {
if ($user->is_active == true) {
return $user;
} else {
return null;
}
});
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.