Laravel在尝试访问页面时将我重定向到了家

时间:2017-04-19 18:36:31

标签: laravel laravel-5

我正在尝试访问名为doctorloginform的视图,但每次尝试访问它时,我都会被重定向到所有人,然后将我重定向到普通用户登录页面(因为页面'all'要求您记录在)。任何帮助表示赞赏

Web.php

Route::get('doctorloginform', 'DoctorLoginController@showLoginForm')->name('doctorlogin');

Route::post('doctorloginsubmit', 'DoctorLoginController@login')->name('doctorloginsubmit');

DoctorLoginController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth; 

class DoctorLoginController extends Controller
{
    public function __construct()
    {
$this->middleware('guest:doctor');
    }

    public function showLoginForm()
    {
        return view('login/doctorloginform');
    }

    public function login(Request $request)
    {
        $this->validate($request, [
            'email' => 'required',
            'password' => 'required',
            ]);

if (Auth::guard('doctor')->attempt(['email' => $request->email, 'password' => $request->password])){

    return redirect()->intended(route('appointment/appointmentdetails'));
}
        else 
        {
    return redirect()->back()->withInput($request->only('email'));

    }
}
}

doctorloginform

@if (session('loginError'))
    <div>
        {{ session('loginError') }}

    </div>
@endif
<form action="{{url('doctorloginsubmit')}}" method="POST">
{{ csrf_field() }}
<h1>DOCTOR</h1>
<div>
<label for="title">DOCTOR:</label>
<input type="email" name="email" value="{{old('email')}}" id="email">
</div>
<div id="passwordBox">
<label for="password">Password:</label>
<input type="password" name="password" id="password">
</div>
<div>
<input type="submit" name="submitBtn" value="Login">
</div>


</form>

Redirectifauthenticated

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/all');
        }

        return $next($request);
    }
}

1 个答案:

答案 0 :(得分:2)

在你的构造函数中添加except(),这样你就不需要那个方法的医生保护。

public function __construct()
{
    $this->middleware('guest:doctor')->except('showLoginForm');
}