Guest User

Untitled

a guest
Oct 28th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public function register(){
  2. Auth::extend('adminEloquent', function($app){
  3. // you can use Config::get() to retrieve the model class name from config file
  4. $myProvider = new EloquentUserProvider($app['hash'], 'AppAdminModel')
  5. return new Guard($myProvider, $app['session.store']);
  6. })
  7. $app->singleton('auth.driver_admin', function($app){
  8. return Auth::driver('adminEloquent');
  9. });
  10. }
  11.  
  12. class AdminAuth extends Facade {
  13. protected static function getFacadeAccessor() { return 'auth.driver_admin'; }
  14. }
  15.  
  16. 'aliases' => [
  17. //has to be beneath the 'Auth' alias
  18. 'AdminAuth' => 'AppFacadesAdminAuth'
  19. ]
  20.  
  21. composer require sarav/laravel-multiauth dev-master
  22.  
  23. IlluminateAuthAuthServiceProvider::class
  24.  
  25. SaravMultiauthMultiauthServiceProvider
  26.  
  27. 'multi' => [
  28. 'user' => [
  29. 'driver' => 'eloquent',
  30. 'model' => AppUser::class,
  31. 'table' => 'users'
  32. ],
  33. 'admin' => [
  34. 'driver' => 'eloquent',
  35. 'model' => AppAdmin::class,
  36. 'table' => 'admins'
  37. ]
  38. ],
  39.  
  40. Auth::loginUsingId("user", 1); // Login user with id 1
  41.  
  42. Auth::loginUsingId("admin", 1); // Login admin with id 1
  43.  
  44. // Attempts to login user with email id johndoe@gmail.com
  45. Auth::attempt("user", ['email' => 'johndoe@gmail.com', 'password' => 'password']);
  46.  
  47. // Attempts to login admin with email id johndoe@gmail.com
  48. Auth::attempt("admin", ['email' => 'johndoe@gmail.com', 'password' => 'password']);
Add Comment
Please, Sign In to add comment