1

I want to ask you how to do multi authentication login in laravel using ollieread? Here is my code in auth.php

'multi' => array( 'account' => array( 'driver' => 'eloquent', 'model' => 'users' ), 'user' => array( 'driver' => 'database', 'table' => 'admin' ) ), 'reminder' => array( 'email' => 'emails.auth.reminder', 'table' => 'password_reminders', 'expire' => 60, ), 

Then, this is my controller

function login() { $attributes = \Input::get(); \Auth::account()->attempt(array( 'email' => $attributes['email'], 'password' => $attributes['password'], )); \Auth::user()->attempt(array( 'email' => $attributes['email'], 'password' => $attributes['password'], )); \Auth::account()->check(); \Auth::user()->check(); return \View::make('superAdmin.login'); } public function authenticateAs($type, $user) { $this->app['auth']->$type()->setUser($user); } 

}

I dont get it how to define $attributes. And when i run my code, the result was

"Missing argument 1 for Illuminate\Auth\AuthManager::createDriver(), called in C:\xampp\htdocs\laravelrental\vendor\laravel\framework\src\Illuminate\Support\Manager.php on line 88 and defined".

So how i fixed this problem?

2 Answers 2

3

In app/config/app.php replace:

'Illuminate\Auth\AuthServiceProvider' 

to:

'Ollieread\Multiauth\MultiauthServiceProvider' 
Sign up to request clarification or add additional context in comments.

1 Comment

The error occurs when you don't remove 'Illuminate\Auth\AuthServiceProvider' provider (read once again installation guide)
0

I found that few people (including myself) were a bit lost at times when it comes to figuring out how to use Ollie Read's multi authentication solution. Looking for a multi authentication solution I've come across Ollie Read's https://github.com/ollieread/multiauth and then found https://github.com/fhferreira/auth2 I would personally recommend the latter as the design of this package is such that the Service Provider will create an instance of Auth2 (auth2.php). So unlike Ollie Read's solution you can still use Auth (you will notice that in the other solution we don't replace the original AuthServiceProvider with another one but we do actually add a new MultiAuthServiceProvider keeping the original as well) without problem. I could not get this package installed using composer but downloading the zip file and putting everything into place shouldn't be too difficult. Beware I found a typo in the code which was actually preventing Auth2 from working. In Collection.php on line 51 one should replace

$providers = $this->config->get('auth2::auth2'); 

by

$providers = $this->config->get('auth2.auth2'); 

assuming your config file is in config/auth2.php and you need to authenticate against two different tables/models here's how your config file config/auth2.php should look like

return array( // example 'auth2' => array ( 'user' => array( 'driver' => 'eloquent', 'model' => 'User', 'table' => 'users' ), 'admin' => array( 'driver' => 'eloquent', 'model' => 'Admin', 'table' => 'admins' ) ) ); 

Now as I mentioned it Auth still allows us to authenticate against the default User model. So one could actually use Auth for users and Auth2 for admin in which case the config file would be

return array(

 // example 'auth2' => array ( 'admin' => array( 'driver' => 'eloquent', 'model' => 'Admin', 'table' => 'admins' ) ) ); 

You can test everything is working fine using php artisan tinker. Once in the tinker shell you can query the config file simply by entering

Config::get('auth2') 

Or

Config::get('auth2.name') 

to see the different authentication options offered by the config file for a particular name defined (user, admin). And so on and so forth for the options in the lower levels of the array.

Hope that helps.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.