我是Laravel的新手,并使用Laravel5.7,因为我想对用户使用多种身份验证并使用单独的管理模型。当我提供用户名和密码时,它会重定向到登录页面本身。请指导我进行成功登录 路径为http://127.0.0.1:8000/admin/login
我的LoginController(app / Http / Controllers / Admin / HomeController.php)
<?php
namespace App\Http\Controllers\Admin\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/admin/home';
public function __construct()
{
$this->middleware('guest:admin')->except('logout');
}
public function showLoginForm()
{
return view('admin.auth.login');
}
public function guard()
{
return \Auth::guard('admin');
}
public function logout(Request $request)
{
$this->guard('admin')->logout();
return redirect('/');
}
}
auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'intis_admins'
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'intis_admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
Handler.php
if(in_array('admin',$exception->guards())){
return redirect()->guest('admin/login');
}
web.php(/routes/web.php)
Route::group(['namespace' => 'Admin','prefix'=>'admin'],function(){
Route::get('/',function(){
return redirect()->to('admin/home');
})->name('admin');
// home
Route::get('home','HomeController@index')->name('admin.home');
// login logout
Route::get('login','Auth\LoginController@showLoginForm')->name('admin.login');
Route::post('login','Auth\LoginController@login')->name('admin.login');
Route::post('logout','Auth\LoginController@logout')->name('admin.logout');
login.blade.php(views / admin / login.blade.php)
<form id="sign_in_adm" class="form-vertical" method="POST" action="{{ route('admin.login') }}">
@csrf
<div class="control-group{{ $errors->has('username') ? ' has-error' : '' }}">
<div class="controls">
<div class="main_input_box">
<span class="add-on bg_lg"><i class="icon-user"> </i></span>
<input id="username" type="text" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" name="username" value="{{ old('username') }}" required autofocus>
<!--<input type="text" placeholder="Username" name="username" />-->
@if ($errors->has('username'))
<span class="text-danger"><strong>{{ $errors->first('username') }}</strong></span>
@endif
</div>
</div>
</div>
<div class="control-group{{ $errors->has('password') ? ' has-error' : '' }}">
<div class="controls">
<div class="main_input_box">
<span class="add-on bg_ly"><i class="icon-lock"></i></span>
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
<!--<input type="password" name="password" placeholder="Password" />-->
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="form-actions">
<input class="filled-in chk-col-pink" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label for="rememberme">Remember Me</label>
<span class="pull-left"><a href="#" class="flip-link btn btn-info" id="to-recover">Lost password?</a></span>
<span class="pull-right"><input type="submit" value="Login" href="index.html" class="btn btn-success" /> </span>
</div>
</form>
当我提供用户名和密码时,它会重定向到登录页面本身。请指导我进行成功登录