I have the application which have 2 Auth system. there is : User and Company.
is there a way to make an single Auth System for that's different models, without using any package (auth) ?
I will tell you step by step.
In default config laravel4, see on app/config/auth.php
, you will see the default models is a user. and you want to login as a company.
Trying to login, if Auth credentials is false (this means your user credential in users table is unavailable), Change auth models to Company.
the code is
if(Auth::attempt($credentials)){
// User is login
}
else{
// trying login as company
// setting auth model to Company
Config::set('auth.model', 'Company');
$auth = Auth::createEloquentDriver();
Auth::setProvider($auth->getProvider());
if(Auth::attempt($credentials)){
//if sucess
Session::put('isCompany', true);
}
else{
//login fails
}
}
//in routes.php
if (Session::has('isCompany')) {
Config::set('auth.model', 'Company');
}
normally you can show Auth details, by using Auth::user()
I hope this can help you, thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With