Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Login redirecting back to Admin Login page. #45

Open
HoodLegend opened this issue Aug 13, 2021 · 0 comments
Open

Admin Login redirecting back to Admin Login page. #45

HoodLegend opened this issue Aug 13, 2021 · 0 comments

Comments

@HoodLegend
Copy link

I followed dev marketers tutorial to implement multiple authentication in my Laravel app. However, when i try to login as an admin it stays on the admin login page and does not go to the target page. Can someone assist on how i can gp about this issue,

The following are the is my admin controller
``<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class AdminLoginController extends Controller
{

use AuthenticatesUsers;

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


public function showLoginForm() {
  return view('auth.admin-login');
}

public function login(Request $request) {
  // validate the form data here
  $this->validate($request, [
    'email' => 'required|email',
    'password' => 'required|min:8'
  ]);

  // Attempt to log the user in
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
  // if successful, then redirect to their intended location
  return redirect()->intended(route('admin.dashboard'));
}

   return redirect()->back()->withInput($request->only('email', 'remember'));

}

}
``

and this is my route that consists of the admin related views
`` Route::prefix('admin')->group(function() {

Route::get('/login', 'App\Http\Controllers\Auth\AdminLoginController@showLoginForm')->name('admin.login');

Route::post('/login', 'App\Http\Controllers\Auth\AdminLoginController@login')->name('admin.login.submit');

Route::get('/', 'App\Http\Controllers\AdminController@index')->name('admin.dashboard');;

Route::get('/{id}/',[CarsController::class, 'getCar'] )->where('id', '[0-9]+')->middleware('auth:admin');;

Route::get('/cars',[CarsController::class, 'getCars'])->middleware('auth:admin')->name('admin.cars');;;

Route::get('/create-car/',[CarsController::class, 'createCar'] )->middleware('auth:admin')->name('admin.cars');;;

Route::post('/store-car/',[CarsController::class, 'storeCar'])->middleware('auth:admin');;;

Route::get('/{id}/edit',[CarsController::class, 'editCar'])->where('id', '[0-9]+')->middleware('auth:admin');;;

Route::post('/cars/edit-car/{id}',[CarsController::class, 'storeEditedCar'])->where('id', '[0-9]+')->middleware('auth:admin');;;

});``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant