I have a project in Laravel 5.4 and I want to use the authentication system that it brings, but with the information that is found in another table that has already been created through the migrations.
The truth is that I have surfed all over the internet and I have seen the documentation, but on both sides I have not managed to get answers that allow me to do what I need.
To the maximum that I have arrived it is to realize the authentication but without redirection, that is to say, the data are sent and then I arrive at the same view of login.
I leave the code of what I wear.
LoginController
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller {
use AuthenticatesUsers;
public function username() {
return 'usuario';
}
public function __construct() {
}
public function showLoginForm() {
return view('auth.login');
}
public function login(Request $request) {
// Validate the form data
$this->validate($request, [
'password' => 'required|min:2'
]);
// Attempt to log the user in
if (Auth::guard()->attempt(['usuario' => $request->usuario, 'password' => $request->password], $request->remember)) {
// if successful, then redirect to their intended location
return redirect()->intended(route('admin.dashboard'));
}
// if unsuccessful, then redirect back to the login with the form data
return redirect()->back()->withInput($request->only('usuario', 'remember'));
}
}
The rest is practically by default. It is worth mentioning that it generates the authentication structure with:
php artisan make:auth
Answer Shaz
Thanks for answering. I have done what you indicate, I add the code of how I have both files
app / access (model)
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Acceso extends Authenticatable
{
use Notifiable;
protected $guard = 'users';
protected $table = 'acceso';
protected $fillable = ['id', 'rol_id', 'personal_id', 'usuario', 'contraseña', 'activo'];
protected $primaryKey = 'id';
public function rol(){
return $this->belongsTo('App\Rol');
}
public function personal(){
return $this->belongsTo('App\Personal');
}
}
config / auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Acceso::class,
],