dev-techguy/laravel-multiple-guards

This library helps one to handle multiple guards. Read through the read me.

v1.1.9 2023-02-24 12:59 UTC

README

techguy.png

Big Things, Start Small
68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6465762d746563686775792f6c61726176656c2d6d756c7469706c652d6775617264732e737667 68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6465762d746563686775792f6c61726176656c2d6d756c7469706c652d6775617264732e737667 68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6465762d746563686775792f6c61726176656c2d6d756c7469706c652d6775617264732e737667 68747470733a2f2f706f7365722e707567782e6f72672f6465762d746563686775792f6c61726176656c2d6d756c7469706c652d6775617264732f762f737461626c65 68747470733a2f2f706f7365722e707567782e6f72672f6465762d746563686775792f6c61726176656c2d6d756c7469706c652d6775617264732f646f776e6c6f616473

68747470733a2f2f63646e2e6c796e64612e636f6d2f636f757273652f3739383439362f3739383439362d3633373331333839383839303636323735332d313678392e6a7067

Introduction

This library helps one to handle multiple guards. Read through to understand how to use it.

Installing

The recommended way to install laravel-multiple-guards is through Composer.

# Install package via composer
composer require dev-techguy/laravel-multiple-guards

Next, run the Composer command to install the latest stable version of dev-techguy/laravel-multiple-guards:

# Update package via composer
 composer update dev-techguy/laravel-multiple-guards --lock

After installing, the package will be auto discovered, But if need you may run:

# run for auto discovery <-- If the package is not detected automatically -->
composer dump-autoload

Then run this, to get the config/laravel-multiple-guards.php for your own configurations:

# run this to get the configuration file at config/laravel-multiple-guards.php <-- read through it -->
php artisan vendor:publish --provider="LaravelMultipleGuards\LaravelMultipleGuardsServiceProvider"

A config/laravel-multiple-guards.php file will be created, follow the example below to define your guards.

# set all the guards to use within the system
SYSTEM_GUARDS=admin,web

Usage

Follow the steps below on how to use the laravel-multiple-guards:

How to use the Library

How to use the guards within your controller...

class HomeController extends Controller
{
    use FindGuard;
    
        /**
         * Create a new controller instance.
         *
         * @return void
         */
        public function __construct()
        {
            $this->middleware($this->setGuardMiddleware()); //@todo this sets the middleware automatically i.e auth, auth:admin that you have defined in the config/auth.php
        }
    
        /**
         * Show the application dashboard.
         *
         * @return Renderable
         */
        public function index()
        {
            return view('home');
        }
    
        /**
         * get authenticated user
         */
        public function getUser()
        {
            return $this->findGuardType()->user();
        }
    
        /**
         * logout user
         * @return RedirectResponse
         */
        public function logout()
        {
            $this->findGuardType()->logout();
            return redirect()->route('login');
        }
}

/**
 * How to get the guard name
 * authorized
*/
 return $this->findGuardType(true); //@todo this returns the guard name i.e web , admin

Version Guidance

Version Status Packagist Namespace Repo
1.x Latest dev-techguy/laravel-multiple-guards LaravelMultipleGuards v1.1.6

Security Vulnerabilities

For any security vulnerabilities, please email to Vincent Ososi.

License

This package is open-source, licensed under the MIT License.