沃梦达 / 编程问答 / php问题 / 正文

类 AppHttpControllersUserController 不存在

Class AppHttpControllersUserController Does Not Exist(类 AppHttpControllersUserController 不存在)

本文介绍了类 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 不存在

基础教程推荐