-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use custom guard-name throughout Voyager * Apply fixes from StyleCI (#4382) * Remove voyager.user.namespace config and use guard instead * Add docs, fix some small problems Add docs to use a different user-table. Other models use other keys for roles - hardcoded them * Update docs * Hide profile button if custom guard is set and no datatype exists * Update docs Co-Authored-By: Adam Nielsen <[email protected]> * Apply fixes from StyleCI (#4391)
- Loading branch information
Showing
25 changed files
with
162 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,87 @@ | ||
# Custom guard | ||
|
||
Starting with Voyager 1.2 you can define a \(custom\) guard which is used throughout Voyager. | ||
To do so, just bind your auth-guard to `VoyagerAuth`. | ||
Open your `AuthServiceProvider` and add the following to the register method: | ||
To do so, just bind the name of your auth-guard to `VoyagerGuard`. | ||
First, make sure you have defined a guard as per the [Laravel documentation](https://laravel.com/docs/authentication#adding-custom-guards). | ||
After that open your `AuthServiceProvider` and add the following to the register method: | ||
|
||
```php | ||
$this->app->singleton('VoyagerAuth', function () { | ||
return Auth::guard('your-custom-guard'); | ||
$this->app->singleton('VoyagerGuard', function () { | ||
return 'your-custom-guard-name'; | ||
}); | ||
``` | ||
|
||
Now this guard is used instead of the default guard. | ||
|
||
|
||
# Example - using a different model and table for Admins | ||
|
||
First you have to create a new table. Let's call it `admins`: | ||
```php | ||
<?php | ||
Schema::create('admins', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->bigInteger('role_id')->unsigned()->nullable(); | ||
$table->string('name'); | ||
$table->string('email')->unique(); | ||
$table->string('avatar')->nullable()->default('users/default.png'); | ||
$table->string('password')->nullable(); | ||
$table->string('remember_token')->nullable(); | ||
$table->text('settings')->nullable()->default(null); | ||
$table->timestamps(); | ||
$table->foreign('role_id')->references('id')->on('roles'); | ||
}); | ||
``` | ||
|
||
and a model which extends Voyagers user-model: | ||
|
||
```php | ||
<?php | ||
|
||
namespace App; | ||
|
||
class Admin extends \TCG\Voyager\Models\User | ||
{ | ||
|
||
} | ||
``` | ||
|
||
Next, create a guard named `admin` in your `config/auth.php`: | ||
``` | ||
'guards' => [ | ||
'admin' => [ | ||
'driver' => 'session', | ||
'provider' => 'admins', | ||
], | ||
// ... | ||
], | ||
``` | ||
And a user provider called `admins`: | ||
``` | ||
'providers' => [ | ||
'admins' => [ | ||
'driver' => 'eloquent', | ||
'model' => App\Admin::class, | ||
], | ||
// ... | ||
], | ||
``` | ||
|
||
Next you have to tell Voyager to use your new guard. | ||
Open you `AppServiceProvider.php` and add the following to the `register` method: | ||
|
||
```php | ||
public function register() | ||
{ | ||
$this->app->singleton('VoyagerGuard', function () { | ||
return 'admin'; | ||
}); | ||
} | ||
``` | ||
|
||
{% hint style="info" %} | ||
Please note that the user-bread is still responsible to edit users - not admins. | ||
Create a BREAD for the `admins` table if you want to change Admins. | ||
{% endhint %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.