2017 © Pedro Peláez
 

library pseudo

Guest user library for Laravel

image

agilesdesign/pseudo

Guest user library for Laravel

  • Monday, June 25, 2018
  • by jrseliga
  • Repository
  • 1 Watchers
  • 10 Stars
  • 921 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 5 Versions
  • 55 % Grown

The README.md

pseudo

Guest user library for Laravel, (*1)

Branch
master build status coverage report
dev build status coverage report

Description

pseudo adds the ability for guests permissions within Laravel's authentication functionality., (*2)

Installation

Include through composer

composer require agilesdesign/pseudo, (*3)

Add to provider list
'providers' => [
    Pseudo\Providers\PseudoServiceProvider::class,
];

Overview

Comparison to default Laravel behavior, (*4)

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

Configuration

Update Guard Driver(s)

config/auth.php, (*5)

'guards' => [
    // To use with web guard
    'web' => [
        'driver' => 'pseudo',
        'provider' => 'users',
    ],

    // To use with api guard
    'api' => [
        'driver' => 'pseudo-token',
        'provider' => 'users',
    ],
],

Register Service Provider

Manually registering the ServiceProvider is only necessary if your Laravel application is version 5.4.* or before. config/app.php, (*6)

'providers' => [
    /*
     * Package Service Providers...
     */
    \Pseudo\Providers\PseudoServiceProvider::class,
],

Usage

An instance of Pseudo\Auth\Guest is resolved from Laravel's Service Container when Pseudo/Contracts/GuestContract is requested., (*7)

This binding is registered in the supplied ServiceProvider:, (*8)

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:, (*9)

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., (*10)

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

The Versions

25/06 2018

dev-dev

dev-dev

Guest user library for Laravel

  Sources   Download

MIT

The Requires

  • php 7.*

 

The Development Requires

by Justin Seliga

30/07 2017

dev-master

9999999-dev

Guest user library for Laravel

  Sources   Download

MIT

The Requires

  • php 7.*

 

The Development Requires

by Justin Seliga

30/07 2017

v1.0.0-rc.1

1.0.0.0-RC1

Guest user library for Laravel

  Sources   Download

MIT

The Requires

  • php 7.*

 

The Development Requires

by Justin Seliga

29/06 2017

v1.0.0-alpha.2

1.0.0.0-alpha2

Guest user library for Laravel

  Sources   Download

MIT

The Requires

  • php 7.*

 

The Development Requires

by Justin Seliga

22/11 2016

v1.0.0-alpha.1

1.0.0.0-alpha1

Guest user library for Laravel

  Sources   Download

MIT

The Requires

  • php 7.*

 

by Justin Seliga