Class AppHttpControllersUserController Does Not Exist(类 AppHttpControllersUserController 不存在)
问题描述
加载路由/users 或/user/add 时出现问题并返回错误;
Having the issue when loading the route /users or /user/add and being return an error of;
Route.php 第 280 行中的 ReflectionException:类AppHttpControllersAppControllersUserController 不存在
ReflectionException in Route.php line 280: Class AppHttpControllersAppControllersUserController does not exist
UserController 确实存在,但它不在我的控制器文件夹中的文件夹中.
The UserController does exist and it is not in a folder within my controllers folder.
我的路由文件;
Route::group(['middleware' => 'auth'], function(){
Route::get('/route/selector', 'PagesController@selectRoute');
// Admin Only //
Route::group(['middleware' => 'isAdmin'], function(){
Route::get('/admin', 'AdminController@index');
Route::get('/users', 'UserController@index');
Route::get('/user/add', 'UserController@getAdd');
Route::post('/user/add', 'UserController@postAdd');
Route::get('/user/edit/{id}', 'UserController@getEdit');
Route::post('/user/edit/{id}', 'UserController@postEdit');
Route::get('/user/delete/{id}', 'UserController@delete');
});
});
我的用户控制器;
<?php
namespace AppHttpControllers;
use AppHttpRequests;
use AppUser;
use AppUserTypes;
use Auth;
use Hashids;
use Redirect;
use Request;
use Hash;
class UserController extends Controller
{
public function index(){
$users = User::get();
return view('users.index', compact('users'));
}
public function getAdd(){
$user_type = UserTypes::pluck('user_type', 'id');
return view('users.add', compact('user_type'));
}
public function postAdd(){
$input = Request::all();
$password = str_random(8);
User::create(
'email' => $input['email'],
'password' => Hash::make($password),
'first_name' => $input['first_name'],
'surname' => $input['surname'],
'phone_number' => $input['phone_number'],
'user_type' => $input['user_type'],
);
return Redirect::action('UserController@index');
}
public function getEdit($id){
}
public function postEdit($id){
}
public function delete($id){
User::find(current(Hashids::decode($id)))->delete();
return Redirect::action('UserController@index');
}
}
当我删除 User::create();部分错误消失,是否与此有关?
推荐答案
Laravel 8.x 更新有不同的路由使用方式.
Laravel 8.x update has a different way of using routes.
以前是:
Route::get('/', 'PagesController@index');
现在变成了
Route::get('/',[PagesController::class, 'index']);
注意:不要忘记在顶部的 routes(web.php) 文件中导入(使用)您的控制器.喜欢:
use AppHttpControllersPagesController;
这篇关于类 AppHttpControllersUserController 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:类 AppHttpControllersUserController 不存在
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01