Reputation: 494
I'm trying to configure the laravel's auth to fit with my db.
But whatever I do, override properties like protected $table='my_table';
or public function username() { return 'email_user'}
in LoginController, it ignore everything.
Does anyone know how to parameter the auth of laravel with different database ?
Here is what I changed in LoginController:
public function username()
{
return 'email_user';
}
And in the User model :
protected $table = "pays";
protected $primaryKey = "id_user";
public function getAuthPassword() {
return $this->password_user;
}
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name_user', 'surname_user', 'email_user', 'password_user', 'sex_user', 'birth_user', 'address_user',
'city_user', 'pc_user', 'phone_user', 'pic_user', 'status_user', 'license_user', 'urssaf_user',
'remember_token', 'created_at', 'updated_at',
];
EDIT : config/auth.php :
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
]; LoginController :
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller { /* |-------------------------------------------------------------------------- | Login Controller |-------------------------------------------------------------------------- | | This controller handles authenticating users for the application and | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | */
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function username()
{
return 'email_user';
}
}
Upvotes: 2
Views: 105
Reputation: 368
In your login form keep password field with name=password
:
<input type="text" name="email_user">
<input type="password" name="password">
Upvotes: 2