<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shiftechafrica / laravel-multiple-guards example snippets
# run for auto discovery <-- If the package is not detected automatically -->
composer dump-autoload
# run this to get the configuration file at config/laravel-multiple-guards.php <-- read through it -->
php artisan vendor:publish --provider="LaravelMultipleGuards\LaravelMultipleGuardsServiceProvider"
# set all the guards to use within the system
SYSTEM_GUARDS=admin,web
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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.