TF120
TF120

Reputation: 317

Laravel redirecting me to home when trying to visit page

I'm trying to access a view called doctorloginform, however everytime i try access it, I keep getting redirected to all, which then redirects me to the normal user login page(because the page 'all' requires you to be logged in). Any help is appreciated

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);
    }
}

Upvotes: 1

Views: 403

Answers (1)

Eric Tucker
Eric Tucker

Reputation: 6335

In your constructor add the except() so you're not requiring the doctor guard for that method.

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

Upvotes: 2

Related Questions