Package Data | |
---|---|
Maintainer Username: | jrseliga |
Maintainer Contact: | jseliga@agilesdesign.com (Justin Seliga) |
Package Create Date: | 2016-11-22 |
Package Last Update: | 2018-06-25 |
Home Page: | https://gitlab.com/jrseliga/pseudo |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-18 03:04:48 |
Package Statistics | |
---|---|
Total Downloads: | 12,147 |
Monthly Downloads: | 16 |
Daily Downloads: | 0 |
Total Stars: | 13 |
Total Watchers: | 1 |
Total Forks: | 6 |
Total Open Issues: | 1 |
Guest user library for Laravel
Branch | | | ------- | ------- | ------- | master | | dev | |
pseudo adds the ability for guests permissions within Laravel's authentication functionality.
composer require agilesdesign/pseudo
'providers' => [
Pseudo\Providers\PseudoServiceProvider::class,
];
Comparison to default Laravel behavior
Auth::check() // true if User false if Pseudo/Contracts/GuestContract
Auth::user() // returns instance of Pseudo/Contracts/GuestContract instead of null if no user found
@can() // no longer automatically fails if not authenticated, allows Gate to be checked
config/auth.php
'guards' => [
// To use with web guard
'web' => [
'driver' => 'pseudo',
'provider' => 'users',
],
// To use with api guard
'api' => [
'driver' => 'pseudo-token',
'provider' => 'users',
],
],
Manually registering the ServiceProvider is only necessary if your Laravel application is version 5.4.* or before.
config/app.php
'providers' => [
/*
* Package Service Providers...
*/
\Pseudo\Providers\PseudoServiceProvider::class,
],
An instance of Pseudo\Auth\Guest
is resolved from Laravel's Service Container when Pseudo/Contracts/GuestContract
is requested.
This binding is registered in the supplied ServiceProvider:
public function register()
{
$this->app->bind(GuestContract::class, Guest::class);
}
You may override this by providing your own GuestUser
class that implements Pseudo/Contracts/GuestContract
and rebinding the interface:
class GuestUser extends User implements GuestContract
{
//You can override any attribute by using Eloquent Accessors
public function getNameAttribute(){
return 'Guest User';
}
}
this->app->bind(\Pseudo\Contracts\GuestContract::class, \App\GuestUser::class);
Policy checks can still be type-hinted for Laravel's App\User
since Pseudo\Auth\Guest
extends it.
Gate::define('create-article', function ($user, $article) {
if($user instanceof Pseudo\Auth\Guest)
{
// logic for guest
}
else
{
// logic for authenticated
}
});