我的 Laravel 5.4 项目多重身份验证系统中存在问题。问题是Laravel将我重定向到一个空白页面,让我们说而不是admin / home它将我重定向到一个空白页面有URI / admin 这是我的迁移首先是 admin 。
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAdminsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admins', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('adress');
$table->string('email')->unique();
$table->string('password');
$table->integer('cin')->unique()->unsigned();
$table->integer('phone')->unique()->unsigned();
$table->string('sexe');
$table->boolean('activation')->default(0);
$table->string('token',254)->nullable();
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('admins');
}
}
这是管理模型实现:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\notifications\AdminResetPasswordNotification;
class Admin extends Authenticatable
{
use Notifiable;
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new AdminResetPasswordNotification($token));
}
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'first_name' , 'last_name' , 'adress', 'email' , 'password' , 'cin' , 'phone' , 'sexe', 'activation'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function roleUser(){
return $this->hasOne('App\RoleUser');
}
public function salary(){
return $this->hasOne('App\Salary');
}
public function images()
{
return $this->morphMany('App\Image','imageable');
}
public function subjects()
{
return $this->hasMany('App\Subject');
}
public function documents()
{
return $this->hasMany('App\Document');
}
}
第三个是角色用户迁移:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRoleUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('role_users', function (Blueprint $table) {
$table->increments('id');
$table->integer('admin_id')->unsigned()->index();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('role_users');
}
}
RoleUser MODEL
namespace App;
use Illuminate\Database\Eloquent\Model;
class RoleUser extends Model
{
protected $fillable = [
'name' , 'admin_id'
];
public function admin(){
return $this->belongsTo('App\Admin');
}
}
所以我在视图中的admin文件夹中复制了auth文件夹视图,并且我更改了操作。
@extends('layouts.subhome')
@section('content')
@include('includes.wow')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Login sfdsgf</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('admin.login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ route('admin.password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div><br>
<br>
<br>
<br>
<br>
<br>
@endsection
这是登录控制器:
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
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 = 'admin/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//$this->middleware('guest:admin', ['except' => 'logout']);
}
/**
* Send the response after the user was authenticated.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function sendLoginResponse(Request $request)
{
$request->session()->regenerate();
$this->clearLoginAttempts($request);
foreach ($this->guard()->user()->roleUser() as $role) {
if ($role->name == 'Amministratore') {
return redirect('admin/home');
}elseif($role->name == 'Avocate') {
return redirect('avocate/home');
}elseif($role->name == 'Reddattore Professionale') {
return redirect('reddattoreprofessionale/home');
}elseif($role->name == 'Reddattore Apprendista') {
return redirect('reddattoreapprendista/home');
}elseif($role->name == 'Segretario') {
return redirect('segretario/home');
}else{
return redirect('/');
}
}
}
/**
* Show the application's login form.
*
* @return \Illuminate\Http\Response
*/
public function showLoginForm()
{
return view('admin.login');
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard('admin');
}
}
这是路线列表:
<?php
Route::get('/', function () {
return view('welcome');
})->name('welcome');
Route::get('/subscribe', function () {
return view('admSubscribe');
})->name('adminsub');
Route::GET('/sottoscrizione/lavoro', 'AdminController@index');
Route::RESOURCE('/sottoscrizione/lavoro', 'AdminController');
Auth::routes();
Route::GET('/home', 'HomeController@index');
Route::GET('admin/home','AdminController@showHome')->name('admin.home');
Route::GET('avocate/home','AvocatController@showHome')->name('avocat.home');
Route::GET('reddattoreprofessionale/home','ProfessionalRedactorController@showHome')->name('redpro.home');
Route::GET('reddattoreapprendista/home','TrainerRedactorController@showHome')->name('redtrain.home');
Route::GET('segretario/home','SecretaryController@showHome')->name('segretario.home');
Route::GET('admin','Admin\LoginController@showLoginForm')->name('admin.login');
Route::POST('admin','Admin\LoginController@login');
Route::POST('admin-password/email','Admin\ForgotPasswordController@sendResetLinkEmail')->name('admin.password.email');
Route::GET('admin-password/reset','Admin\ForgotPasswordController@showLinkRequestForm')->name('admin.password.request');
Route::POST('admin-password/reset','Admin\ResetPasswordController@reset');
Route::GET('admin-password/reset/{token}','Admin\ResetPasswordController@showResetForm')->name('admin.password.reset');
好的,请帮忙,我已经在这个问题上被困了4个星期。