1

I'm trying to implement admin/users login with laravel 5.5. I've created the Admin model, exactly the same as the user one, and set the guards for the admin. But during login, the guards are not being passed:

This is my AdminController:

<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class AdminController extends Controller{
 use AuthenticatesUsers;
 protected $guard = 'admin';
 public function showLoginForm(){
 return view('admin')->with(['title' => 'Panel de Administrador - Iniciar Sesión', 'bodyClass' => 'admin-view']);
 }
}

I tried to debug, and went into the vendor folder, to AuthenticatesUsers class, and debugged the request:

enter image description here

As you can see, it's using the User model and the web guard. Here's on the config file for the guards:

'guards' => [
 'web' => [
 'driver' => 'session',
 'provider' => 'users',
 ],
 'api' => [
 'driver' => 'token',
 'provider' => 'users',
 ],
 'admin' => [
 'driver' => 'session',
 'provider' => 'admins',
 ]
],

and then I have the provider:

'providers' => [
 'users' => [
 'driver' => 'eloquent',
 'model' => App\User::class,
 ],
 'admins' => [
 'driver' => 'eloquent',
 'model' => App\Admin::class
 ]
],
asked Sep 25, 2017 at 23:22

1 Answer 1

0

Nevermind I figured it out. Guard is not a property of the class, it's a function so I have to replace the inherited guard function, and use the Auth facade, like this:

use Illuminate\Support\Facades\Auth;
class AdminController extends Controller{
 use AuthenticatesUsers;
 public function guard(){
 return Auth::guard('admin');
 }
 public function showLoginForm(){
 return view('admin')->with(['title' => 'Panel de Administrador - Iniciar Sesión', 'bodyClass' => 'admin-view']);
 }
}
answered Sep 25, 2017 at 23:48
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.