1. Go to this page and download the library: Download mayoz/laravel-tokens 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/ */
namespace App;
use Mayoz\Token\HasToken;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasToken, Notifiable;
// ...
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TokenController
{
public function __invoke(Request $request)
{
$token = $request->user()->generateToken();
return $token;
}
}
$token = $request->user()->generateToken(10);
namespace App\Providers;
use Mayoz\Token\Generator;
// ...
class AuthServiceProvider extends ServiceProvider
{
// ...
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
// ...
Generator::extend(function () {
return \Ramsey\Uuid\Uuid::uuid4()->toString();
});
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController
{
public function __construct()
{
$this->middleware('auth:api');
}
public function __invoke(Request $request)
{
return [
'user' => $request->user(),
'token' => $request->token(),
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.