Laravel - 目标类 [app\Http\Controllers\ProductsController] 不存在

问题描述 投票:0回答:3

我尝试了几种 stackoverflow 解决方案来解决我的问题,但没有一个可以解决问题。

当我打开 Laravel-Project 并路由到 /products 时,我收到消息: “目标类 [app\Http\Controllers\ProductsController] 不存在”。

这是我的代码的图片:

web.php

use Illuminate\Support\Facades\Route;
use app\Http\Controllers\ProductsController;

Route::get('/products', [ProductsController::class, 'index']);

控制器.php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

ProductsController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ProductsController extends Controller
{
    public function index() {
        return view('products.index');
    }
}

index.blade.php

<html lang="en"> 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>Products</h1>
</body>
</html>

这是我的文件结构的图片: laravel结构

如果你能帮助我,那就太好了,因为我真的需要继续我的 Laravel 教程。

laravel class routes
3个回答
0
投票

SQLSTATE[23000]:违反完整性约束:1048 列“from_phone”不能为空(连接:mysql,SQL:插入

history_transfers
order_code
from_phone
to_phone
amount
message
) ,
msg_log_transfer
,
status
,
updated_at
,
created_at
) 值 (TT_WEB_TRANSFER_TO_BANK, ?, 866620278686, 10000, Chuyển khoảnthanh toán, {"message":""phone" 必须是字符串","success ” :假}, 0, 2024-09-29 19:13:36, 2024-09-29 19:13:36))


-1
投票

再次嘿, 感谢sta的评论我可以解决问题:

“可能是一个拼写错误,请尝试使用 App\Http\Controllers\ProductsController;应用程序应该是 App”

之前(不工作):

use app\Http\Controllers\ProductsController;

解决方案:

use App\Http\Controllers\ProductsController;

伊吉瓦纳兹


-1
投票

就我而言,它使用 PHP 短标签,并且未在服务器上激活。

© www.soinside.com 2019 - 2024. All rights reserved.