njdigitallab / laraauth
An authentication package for laravel
Requires
- php: ^8.4
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Table of Contents
- About
- Installation
- Name
- Login
- Logout
- Registration
- Verify Email
- Forgot Password
- Confirm Password
- Show Site Logo
- Filter Registration Rules
- Filter Registration Attributes
- Custom Styling
About
Laraauth is an authentication package for Laravel.
Installation
Install with composer require njdigitallab/laraauth.
Getting Started
Publish the package assets by running php artisan vendor:publish --tag=laraauth-assets.
Name
By default, laravel user migration comes with the name column only. If you want to work with first and last name instead, take the following steps:
-
Publish the package migration file with
php artisan vendor:publish --tag=laraauth-migrationsthen run thephp artisan migratecommand. Alternatively, You can edit the default laravel user migration file and ignore this step. -
In your
AppServiceProviderboot method, call LaraauthallowFirstAndLastNamemethod. This tells the package that we will be working with first and last name instead of name only.
use NjDigitalLab\Laraauth\Laraauth; /** * Bootstrap any application services. */ public function boot(): void { Laraauth::allowFirstAndLastName(); }
- Update the fillable attributes on the User model.
// If using attributes #[Fillable(['first_name', 'last_name', 'email', 'password'])] // If defining on the model protected $fillable = [ 'first_name', 'last_name', 'email', 'password', ];
Login
Login is available at /login url and needs no configuration.
Logout
To logout, send a post request to the logout route.
<a href="" class="" onclick="event.preventDefault(); document.getElementById('logout-form').submit();"> Logout </a> <form method="POST" style="display: hidden;" action="{{ route('logout') }}"> @csrf </form>
Registration
Registration is available at /register url.
You can disable registration by calling the Laraauth disableRegistration method in your AppServiceProvider register method.
use NjDigitalLab\Laraauth\Laraauth; /** * Register any application services. */ public function register(): void { Laraauth::disableRegistration(); }
If you are using first name and last name for registration, refer to the Name section.
Verify Email
Verify email works as per the Laravel default configuration. Apply the verified middleware to the respective route and implement the Illuminate\Contracts\Auth\MustVerifyEmail contract on the User model.
Forgot Password
Forgot password is available at /forgot-password url and need no configuration.
Confirm Password
Confirm password works as per the Laravel default configuration. Apply the password.confirm middleware to the respective route.
Show Site Logo
If you prefer to show a logo instead of the site name, call the Laraauth showLogo method in your AppServiceProvider boot method and pass the full url to the image file you wish to use.
use NjDigitalLab\Laraauth\Laraauth; /** * Bootstrap any application services. */ public function boot(): void { Laraauth::showLogo(asset('images/logo.png')); }
Filter Registration Rules
You can filter registration rules by calling the Laraauth::filterRegistrationValidationRules() method in your AppServiceProvider register method. It accepts a closure as it's only argument. The current rules array and request object is passed to the closure as arguments.
use NjDigitalLab\Laraauth\Laraauth; /** * Register any application services. */ public function register(): void { Laraauth::filterRegistrationValidationRules(function ($rules, $request) { // Filter rules.... return $rules; }); }
Filter Registration Attributes
You can filter the registration attributes by calling the Laraauth::filterRegistrationAttributes() method in your AppServiceProvider register method. It accepts a closure as it's only argument. The current attributes array and request object is passed to the closure as arguments.
use NjDigitalLab\Laraauth\Laraauth; /** * Register any application services. */ public function register(): void { Laraauth::filterRegistrationAttributes(function ($attributes, $request) { // Filter attributes.... $attributes['name'] = 'Some Name'; return $attributes; }); }
Custom Styling
If you want to use your own styling, you can disable the default stylesheet by adding Laraauth::disableStylesheet() to your AppServiceProvider register method.
use NjDigitalLab\Laraauth\Laraauth; /** * Register any application services. */ public function register(): void { Laraauth::disableStylesheet(); }
