0
I can’t get the user authenticated, so he enters my route with middleware auth... I can log in but I can’t get the user logged in, for example I can’t enter any route with middleware auth and nen 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 Usuario
<?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";
}
post the class
App\Usuario::class
please– novic
@Virgilionovic I’m in the chat stack burst man, anyone appears there ^^
– Joan Marcos
I think there’s something wrong with the setup part... but, I can’t say, because it changed the authentication class?
– novic
what configuration ? type I created this project from scratch just to test and yet still not catching
– Joan Marcos
if you want more information just say that I post, I spent the day hj trying to solve this ...
– Joan Marcos
briefcase
config\Auth.php
but, I don’t know why it doesn’t have to test, but, don’t need to change the authentication class that already comes ready ...!!! I see the staff changing only to add fields, because, does not add in the same understood.– novic
Let’s go continue this discussion in chat.
– Joan Marcos