Download the PHP package jsdecena/laravel-passport-multiauth without Composer
On this page you can find all versions of the php package jsdecena/laravel-passport-multiauth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-passport-multiauth
Laravel Passport Multi-Authentication middleware
Laravel passport default behavior is to authenticate your user
on the users
table.
While this is good enough for most of the apps, sometimes we need to tweak it a little bit if there is a new need arises.
I created this middleware because I need a few user groups that would access the app and in every user group there are roles.
How to install
-
In your terminal, run
composer require jsdecena/laravel-passport-multiauth
or add this in yourcomposer.json
-
Add this line in your
config/app.php
-
Add this in your
app\Http\Kernel.php
- Also in your
routes/api.php
Trivia: Why mmda? This is because in the Philippines, they are the one that handles the traffic :sweat_smile:
- And in the
config/auth.php
In your controller, you can access the user logged in via
auth()->guard('customer')->user()
- Your
Customer
model should extend withAuthenticatable
and use theNotifiable
andHasApiTokens
traits
Note that you need the
Customer
model or any model that you need to authenticate with.
-
Migrate the customer table
php artisan vendor:publish --tag=migrations
-
And in your controller:
App\Http\Controllers\Auth\CustomerTokenAuthController.php
- The request to authenticate must have the
provider
key so the system will know which user is to authenticate with
eg.
- The request to authenticate must have the
If the provider parameter is not passed, it will default looking into the
users
table as usual.