I did a manual authentication in Laravel 5.4 and I can not get it to return true the function.
In my database, enter a record from the database administrator with username = admin and password = admin. (I also tried to create the username and password from a laravel form and nothing)
here I leave the code of my files
LoginController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
public function store( Request $request ){
if(Auth::attempt(['username' => 'admin', 'password' => 'admin'])){
return "ok";
}else{
return "error";
}
}
}
Obviously the username and password are hard-coded here so that you do not have to enter them again and again.
User.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
class Usuario extends Eloquent implements Authenticatable
{
use AuthenticableTrait;
protected $fillable = ['username', 'password'];
}
login form
{!!Form::open(['route' => 'login.store' ,'method' => 'POST'])!!}
<div class="form-group">
{!!Form::label('Usuario')!!}
{!!Form::text('user', null, ['class' => 'form-control'])!!}
</div>
<div class="form-group">
{!!Form::label('Contraseña')!!}
{!!Form::password('password', ['class' => 'form-control'])!!}
</div>
<div class="form-group">
{!!Form::submit('Ingresar', ['class' => 'btn btn-primary btn-lg
btn-block'])!!}
</div>
{!!Form::close()!!}
I know that the function arrives, since it is giving me "error" as it can be seen in the logincontroller, in the part of the else.
I think that it is not correctly comparing the password since I did a test to change the name of the column 'username' in the database and I throw an error, but when changing the name of the column 'password' only he returned false and no error of Laravel.