Laravel -Target类[App \ HTTP \ Controllers \ ProductsController]不存在
我为解决问题尝试了几种Stackoverflow解决方案,但是没有一个可以解决问题。
当我打开laravel项目和到达 /产品的路线时,我会收到消息: “目标类[App \ HTTP \ Controllers \ productsController]不存在”。
这是我的代码的图片:
web.php
use Illuminate\Support\Facades\Route;
use app\Http\Controllers\ProductsController;
Route::get('/products', [ProductsController::class, 'index']);
controller.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.blade.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>
< strong>这是我的档案片段的图片: laravel结构
如果您能帮助我,那真是太好了,因为我真的需要继续下去我的Laravel教程。
I tried several stackoverflow solutions for my problem, but none could fix the problem.
When i open my Laravel-Project and route to /products, i get the message:
"Target class [app\Http\Controllers\ProductsController] does not exist".
Here are pictures of my code:
web.php
use Illuminate\Support\Facades\Route;
use app\Http\Controllers\ProductsController;
Route::get('/products', [ProductsController::class, 'index']);
Controller.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>
Here is a picture of my filestructure:
laravel structure
Would be so nice if you could help me, cause i really need to go on with my laravel tutorial.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
再次,
多亏了 sta 的评论,我可以解决这个问题:
“可能是错别字,尝试使用app \ http \ controllers \ products controller; app; app应该是app app'''
(不工作):
解决方案:
iggivannaz: iggivannaz
Hy again,
thanks to sta´s comment i could solve the problem:
"probably a typo, try use App\Http\Controllers\ProductsController; app should be App"
Before(not working):
Solution:
iggivannaz
就我而言,它使用了PHP短标签,并且没有在服务器上激活。
In my case, it was using PHP short tag and it was not activated on server.