gpt4 book ai didi

php - Laravel 9.x 目标类在登录应用程序时不存在错误

转载 作者:行者123 更新时间:2023-12-02 01:37:15 27 4
gpt4 key购买 nike

尝试为管理面板制作一个登录应用程序,以便轻松编辑网站的其余部分。

我有一个名为 AuthController 的 Controller ,它执行多个操作,例如登录-注销。我决定只使用一个 Controller ,而不是两个不同的 Controller 。

当我在资源管理器上访问 /login 时,它返回 Target class [AuthController] does not exist.

问题是什么?我缺少什么?

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

最佳答案

对于laravel 9及以上版本,我觉得你应该这样写:

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

而不是

Route::get('login', [AuthController::class,'showLogin']);

避免常见错误“目标类不存在”。如果您键入最下面的那个,即使您添加此代码也无法正常工作,并且还会返回错误

use App\Http\Controllers\AuthController;

关于php - Laravel 9.x 目标类在登录应用程序时不存在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72159986/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com