PHP code example of esalazarv / multiauth

1. Go to this page and download the library: Download esalazarv/multiauth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

esalazarv / multiauth example snippets


    'Ollieread\Multiauth\MultiauthServiceProvider',

	'Ollieread\Multiauth\Passwords\PasswordResetServiceProvider',

    return [

		'driver' => 'eloquent',

		'model' => 'App\User',

		'table' => 'users',

		'password' => [
        		'email' => 'emails.password',
        		'table' => 'password_resets',
        		'expire' => 60,
        	],

	];

    return [

		'multi'	=> [
			'admin' => [
				'driver' => 'eloquent',
				'model'	=> 'App\Admin',
			],
			'client' => [
				'driver' => 'database',
				'table' => 'clients',
				'email' => 'client.emails.password',
			],
			'other' => [
				'driver' => 'customDriver',
				'model'	=> 'App\Other',
			],
		],

		'password' => [
        		'email' => 'emails.password',
        		'table' => 'password_resets',
        		'expire' => 60,
        	],

	];

    Auth::admin()->attempt(array(
    	'email'		=> $attributes['email'],
    	'password'	=> $attributes['password'],
    ));
    Auth::client()->attempt(array(
    	'email'		=> $attributes['email'],
    	'password'	=> $attributes['password'],
    ));
    Auth::admin()->check();
    Auth::client()->check();

	Auth::admin()->get();

	/** You can switch users as needed **/
	Auth::uses('admin');

	/** Accessing the user using the 'user()' (original method) **/
	if(Auth::user()->check()){
		//
	}

	/** Accessing the user using the 'get()' (additional method)  **/
	if(Auth::get()->check()){
		//
	}


	if(Auth::admin()->user()->check()){
		//
	}

	if(Auth::admin()->get()->check()){
		//
	}

	Auth::impersonate('client', 1, true);

	Auth::admin()->impersonate('client', 1, true);

	/** @return boolean **/
	if(Auth::isImpersonated()){
		//
	}

	/** @return string | null **/
	Auth::getImpersonatorName();

	/** @return string | null **/
	Auth::client()->getImpersonatorName();

    public function authenticateAs($type, $user) {
      $this->app['auth']->$type()->setUser($user);
    }