【发布时间】:2026-01-17 09:20:04
【问题描述】:
我正在关注如何创建 laravel 包的教程。
我正在使用 Laravel v8.42.1 (PHP v7.4.3) 和 jetstream 包。
我一直在为我的包创建控制器,尝试通过 laraval 应用程序 ( TestVendor\TestPackage\src\routes.php 被主应用程序识别: 并且是从我的 ServiceProvider 类加载的: 我的命名空间通常也正确地写在我的包的 composer.json 中: 我在 src/Http/Controllers/PlaygroundController.php 中有我的 PlaygroundController: 视图也在正确的包中。
我正在使用https://github.com/Jeroen-G/laravel-packager 来搭建我的包裹。
是否有多个作曲家自动加载和作曲家更新。 似乎我的控制器在主应用程序中无法识别,我认为我的名称间距不正确? 我已经看过了:Target class [TestVendor\TestPackage\Http\Controllers\PlaygroundController] does not exist.
use TestVendor\TestPackage\Http\Controllers\PlaygroundController;
use Illuminate\Support\Facades\Route;
Route::get('/playground', [PlaygroundController::class, 'index']);
$this->loadViewsFrom(__DIR__.'/resources/views', 'playground');
loadRoutesFrom(__DIR__.'/routes.php');
"autoload": {
"psr-4": {
"TestVendor\\TestPackage\\": "src/"
}
},
namespace TestVendor\TestPackage\Http\Controllers;
use Illuminate\Routing\Controller;
class PlaygroundController extends Controller
{
public function index()
{
return view('playground::hello');
}
}
【问题讨论】: