I can not get the user to be authenticated, so he enters my route with the auth middleware ... I can log in but I can not get the user logged in, for example I can not enter any route with middleware auth and nen to use no helper method Auth :: user () ...
Route
Route::group(['middleware' => 'auth'], function () {
Route::get('/usuario',['uses' => 'UsuarioController@index','as' => 'index']);
});
Route::get('/login',['uses' => 'UsuarioController@login','as' => 'login']);
Route::post('/login',['uses'=>'UsuarioController@checkLogin','as' => 'VerificarLogin']);
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use Auth;
class UsuarioController extends Controller{
public function login () {
return view('Inicial.login');
}
public function index () {
return view('usuario.index_Usuario');
}
public function checkLogin (Request $request){
//$credentials = ['email'=>$request->get('email'),'password'=>$request->get('senha')];
$email = $request->get('email');
$password = $request->get('senha');
if (Auth::attempt(['email' => $email, 'password' => $password])) {
return redirect()->route('index');
}else {
return 0;
}
}
}
Auth.php
<?php
return [
'defaults' => [
'guard' => 'usuario',
'passwords' => 'users',
],
'guards' => [
'usuario' => [
'driver' => 'session',
'provider' => 'usuario',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'usuario' => [
'driver' => 'eloquent',
'model' => App\Usuario::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];
App \ User
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Usuario extends Authenticatable
{
protected $fillable = ['nome','email','password'];
// protected $fillable = ['Usuario_Nome','password','email','Usuario_DtNascimento','Usuario_Role']; //fillable para inserção em massa
protected $table = "usuarios";
}