已关闭此问题为not reproducible or was caused by typos。它目前不接受回答。
此问题是由打印错误或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这一个是解决的方式不太可能帮助未来的读者。
4天前关闭。
Improve this question
我已经为Laravel创建了一个包并将其发布到https://packagist.org/。
在Laravel框架中,我使用compser composer require eraufi/crud
下载了它
现在当我运行composer dump-autoload
时,我得到这个错误Target class [Eraufi\Src\GenerateCRUDCommand] does not exist.
我也问过ChatGPT,但没有运气。
app\Console\Kernel.php:
namespace App\Console;
use Eraufi\Src\GenerateCRUDCommand;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
GenerateCRUDCommand::class,
];
}
vendor\eraufi\crud\composer.json
{
"name": "eraufi/crud",
"description": "A package for generating CRUD operations in Laravel",
"version": "0.0.1",
"authors": [
{
"name": "Mohufi",
"email": "[email protected]"
}
],
"require": {
"php": "^8.1",
"laravel/framework": "^10.10"
},
"autoload": {
"psr-4": {
"eraufi\\crud\\": "src/"
}
}
}
vendor\eraufi\crud\src\GenerateCRUDCommand.php
<?php
namespace Eraufi\Crud;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str; // Import the Str class
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
class GenerateCRUDCommand extends Command
{
protected $signature = 'crud:generate {model}';
protected $description = 'Generate CRUD operations for a model based on the database table';
public function handle()
{
$model = $this->argument('model');
$tableName = Str::snake($model);
$question = [
'generateView' => $this->confirm('Generate Views?'),
'isEducationl' => $this->confirm('Are you Using this for Educational Purposes? (Adds Comments)'),
];
$columns = Schema::getColumnListing($tableName);
$this->requestCodes($model, $columns, $question);
$this->controllerCodes($model, $columns, $question);
$this->routeCodes($model, $question);
if ($question['generateView']) {
$this->indexViewCodes($model, $columns);
$this->createViewCodes($model);
$this->createEditCodes($model);
$this->createShowCodes($model);
}
}
}
1条答案
按热度按时间mpbci0fu1#
问题是
composer.json
引用的是\\eraufi\\crud
,但文件使用的是namespace Eraufi\Src
,它应该是namespace Eraufi\crud
(并使用适当的情况下,Eraufi\Crud
.)