Boa tarde galera, estive pesquisando na Internet e infelizmente não consegui resolver meu problema.
Preciso fazer autenticação de usuários utilizando o framework Laravel 5.2 porém meu método precisa ser diferente, ou seja, ao invés de utilizar o php artisan make:auth eu preciso fazer autenticação manual dos usuários, no caso Auth::attempt.
O meu problema é que a função está retornando FALSE. As credenciais inseridas estão corretas, porém ainda não consegui.
Configurações:
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' => 'admin@google.com', 'password' => '123'])) {
return 'TRUE';
} else {
return 'FALSE';
}
}
}