PHP code example of robbevw / pseudo

1. Go to this page and download the library: Download robbevw/pseudo 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/ */

    

robbevw / pseudo example snippets


'providers' => [
    Pseudo\Providers\PseudoServiceProvider::class,
];

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

public function register()
{
    $this->app->bind(GuestContract::class, Guest::class);
}

class GuestUser extends User implements GuestContract
{

    //Here you amy overload anything to be specific to your guest user
    public function getNameAttribute(){
        return 'Guest User';
    }
}

this->app->bind(\Pseudo\Contracts\GuestContract::class, \App\GuestUser::class);

Gate::define('create-article', function ($user, $article) {
    if($user instanceof Pseudo\Auth\Guest)
    {
      // logic for guest
    }
    else
    {
      // logic for authenticated
    }
});