I can not log in with manual authentication of laravel 5.4

-1
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    protected $table='administrador';
    public $timestamps=false;

    public function showLoginForm()
    {
        return view('auth.login');
    }

    protected function Login(Request $request)
    {
        if(Auth::attempt(["email"=>$request->get('email'),"password"=>$request->get('password')])){
            return Redirect::to('home');
        } else{

        }
    }

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = 'administracion/reportes/general';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

When I try to change the table for authentication, problems appear.

I have detected that attempt returns true, at the time of addressing the page, it returns me to the login, I do not know why, when it should send me to the home page.

This is the home controller code

   <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('home');
    }
}

This is the ROUTE

Route::get('home', 'HomeController@index')->name('home');
    
asked by Fernando Delcid 30.08.2017 в 00:46
source

2 answers

0

If you want to change the table for authentication, you must do so in the model you have assigned in the config / auth.php, which is by default app \ User.php. The table belongs to the model, not to the controller, because the controller has nothing to do (usually) with the database.

app \ User.php     

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    protected $table='administrador';
    public $timestamps=false;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}
    
answered by 30.08.2017 в 00:51
0

I found a solution to change the constructors in the controllers I used to have something like this inside the constructor $ this-> middleware ('auth')

Now change it to $ this-> middleware ('auto.basic')

Since my login and back to true function in the view does not return me back to the login, the error consists of the guards laravel already works with a specific provider and its guard by default in the login trait to modify it are lost methods that are responsible for establishing the guard.

    
answered by 30.08.2017 в 21:07