2
Good afternoon guys, I’ve been searching on the Internet and unfortunately I could not solve my problem.
I need to authenticate users using the Laravel 5.2 framework but my method needs to be different, that is, instead of using php Artisan make:auth I need to do manual authentication of users, in the case Auth::Attempt.
My problem is that the function is returning FALSE. The credentials entered are correct, but I still can’t.
Settings:
Routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('login', 'LoginController@login');
App User.php
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
protected $table = 'usuarios';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'nome', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password'
];
public function setPasswordAttribute($tmp)
{
return $this->attributes['password'] = trim(\Hash::make($tmp));
}
}
App Controllers Logincontroller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class LoginController extends Controller
{
public function login()
{
if (\Auth::attempt(['email' => '[email protected]', 'password' => '123'])) {
return 'TRUE';
} else {
return 'FALSE';
}
}
}
You are registered in the table users these data in the columns email and password respectively ?
– Diego Souza