I try to use the Laravel/Sanctum in a custom Laravel package. As in a default Laravel application, I added it to the composer file, added the migration and set it up in the routes file.
The next error message appears:
"Auth guard [sanctum] is not defined."
I hope it is even possible to use sanctum in another package?
"require": {
"php": "7.4.*",
"laravel/sanctum": "^2.2"
},
Route::group(['middleware' => 'auth:sanctum'], function () {
Route::post('/approve', ['uses' => 'MemberRequestController@response', 'response' => 'approve'])->name('approve_member_request');
}
/**
*
*/
private function registerRoutes()
{
Route::group($this->routeConfig(), function () {
$this->loadRoutesFrom(__DIR__ . '/../../routes/api.php');
});
}
/**
* @return string[]
*/
private function routeConfig(): array
{
return [
'prefix' => ums::path(),
'namespace' => 'martijn\UMS\Http\Controllers',
'middleware' => ['api', 'auth:sanctum']
];
}
You should publish the Laravel\Sanctum\SanctumServiceProvider
.
It will register the missing guard.