Home > database >  Laravel 9.x Target class does not exist error at login application
Laravel 9.x Target class does not exist error at login application

Time:05-09

trying to make a login application for admin panel to edit rest of the website easily.

I have a controller called AuthController and it performs multiple actions such as login-logout. Instead of two different controllers I decided to use only one.

When I go to /login on my explorer it returns Target class [AuthController] does not exist.

What is the problem? What I am missing?

web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PagesController;
use App\Http\Controllers\ContactUsFormController;
use App\Http\Controllers\AuthController;

Route::get('/', 'App\Http\Controllers\PagesController@index');
Route::get('/about', 'App\Http\Controllers\PagesController@about');
Route::get('/pricing', 'App\Http\Controllers\PagesController@pricing');
Route::get('/completed', 'App\Http\Controllers\PagesController@completed');

Route::get('/contact', [ContactUsFormController::class, 'createForm']);
Route::post('/contact', [ContactUsFormController::class, 'ContactUsForm'])->name('contact.store');


Route::get('login', array(
    'uses' => 'AuthController@showLogin'
  ));
  // route to process the form
  Route::post('login', array(
    'uses' => 'AuthController@doLogin'
  ));
  Route::get('logout', array(
    'uses' => 'AuthController@doLogout'
  ));

AuthController.php

<?php

namespace App\Http\Controllers;

use Redirect;
use Auth;
use Input;
use IlluminateSupportFacadesValidator;
use IlluminateFoundationBusDispatchesJobs;
use IlluminateRoutingController as BaseController;
use IlluminateFoundationValidationValidatesRequests;
use IlluminateFoundationAuthAccessAuthorizesRequests;
use IlluminateFoundationAuthAccessAuthorizesResources;
use IlluminateHtmlHtmlServiceProvider;

class AuthController extends Controller
  {
  public function showLogin()
    {
    // Form View
    return view('login');
    }
  public function doLogout()
    {
    Auth::logout(); // logging out user
    return Redirect::to('login'); // redirection to login screen
    }
  public function doLogin()
    {

    // Creating Rules for Email and Password
    $rules = array(

      'email' => 'required|email', // make sure the email is an actual email
      'password' => 'required|alphaNum|min:8'
      // password has to be greater than 3 characters and can only be alphanumeric and);
      // checking all field
      $validator = Validator::make(Input::all() , $rules);
      // if the validator fails, redirect back to the form
      

if ($validator->fails()){
        return Redirect::to('login')->withErrors($validator) // send back all errors to the login form
        ->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
        }else{

        // create our user data for the authentication
        $userdata = array(
          'email' => Input::get('email') ,
          'password' => Input::get('password')
        );
        // attempt to do the login
        if (Auth::attempt($userdata)){
          // validation successful

          }else{
          // validation not successful, send back to form
          return Redirect::to('checklogin');
          }
        }
      }
    }

CodePudding user response:

write like this :

Route::get('login', 'App\Http\Controllers\AuthController@showLogin');

insted :

Route::get('login', array(
'uses' => 'AuthController@showLogin'));
  • Related