Good afternoon guys, I've been searching the Internet and unfortunately I could not solve my problem.
I need to authenticate users using the Laravel 5.2 framework however my method needs to be different, ie instead of using php artisan make: auth I need to do manual authentication of users, in the Auth :: attempt case.
My problem is that the function is returning FALSE. The credentials entered are correct, but I have not yet been able to.
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';
}
}
}