Download the PHP package zendraxl/laravel-request-null-user without Composer
On this page you can find all versions of the php package zendraxl/laravel-request-null-user. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zendraxl/laravel-request-null-user
More information about zendraxl/laravel-request-null-user
Files in zendraxl/laravel-request-null-user
Package laravel-request-null-user
Short Description Laravel Null Object Pattern for User fetched from Request
License MIT
Informations about the package laravel-request-null-user
Laravel Request Null User
Null Object Pattern for User fetched from Request for Laravel framework.
Install
To install just run following command from terminal:
composer require zendraxl/laravel-request-null-user
Usage
Since the user() method is already taken on \Illuminate\Http\Request object, this package provides owner() method cause it makes some sense that the person that made the request is the owner of that request.
You can use any of these:
-
Dependency Injection Request object
-
Laravel Facade Request object
- Global
request()function
Object returned by the owner() method is an instance of \Zendraxl\LaravelRequestNullUser\Owner. It is a simple wrapper/decorator so \App\User class does not have to be modified.
What this is allowing for is, that it can somewhat guarantee the same API across both \App\User and \Zendraxl\LaravelRequestNullUser\NullUser objects without code duplication and respecting the DRY (Don't Repeat Yourself).
Only method defined on the \Zendraxl\LaravelRequestNullUser\Owner object is isGuest() method. This method will return true if the visitor is not authenticated, and false if the visitor is authenticated.
Defaults
Out of the box \Zendraxl\LaravelRequestNullUser\NullUser comes with following public properties:
All of them can be accessed directly through the \Zendraxl\LaravelRequestNullUser\Owner object:
Each default can be changed by defining following env variables:
Extend
\Zendraxl\LaravelRequestNullUser\Owner object is extendable via Macros since it is using Illuminate\Support\Traits\Macroable trait.
Add isAdmin() method to \Zendraxl\LaravelRequestNullUser\Owner:
Additional isType() methods can be also added to the \Zendraxl\LaravelRequestNullUser\Owner object with env variable ZENDRAXL_USER_TYPES. By adding a comma separated list of types everything will be generated on the fly.
If the database has admin, manager, supervisor, pro user, user types on the \App\User model and this is added to the .env file:
then the following methods will be added to the \Zendraxl\LaravelRequestNullUser\Owner object:
If the property on the \App\User model is not type but something like role, then override it with env variable