使用背包在项目中完成其任务(自动添加其功能)的问题。
来自tutorial:
矿山:
PS C:\Apps\xampp\htdocs\cofour-intern> php artisan blueprint:build
...
PS C:\Apps\xampp\htdocs\cofour-intern> php artisan backpack:crud Product
Controller created successfully.
ErrorException
Undefined variable: position
at C:\Apps\xampp\htdocs\cofour-intern\vendor\backpack\generators\src\Console\Commands\CrudModelBackpackCommand.php:94
90| // the same as the array index - arrays start counting from 0,
91| // IDEs start counting from 1
92|
93| // add CrudTrait
> 94| array_splice($file_array, $position, 0, ' use \\'.$this->crudTrait.';');
95|
96| // save the file
97| $this->files->put($path, implode(PHP_EOL, $file_array));
98|
1 C:\Apps\xampp\htdocs\cofour-intern\vendor\backpack\generators\src\Console\Commands\CrudModelBackpackCommand.php:94
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Undefined variable: position", "C:\Apps\xampp\htdocs\cofour-intern\vendor\backpack\generators\src\Console\Commands\CrudModelBackpackCommand.php")
2 C:\Apps\xampp\htdocs\cofour-intern\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:33
Backpack\Generators\Console\Commands\CrudModelBackpackCommand::handle()
PS C:\Apps\xampp\htdocs\cofour-intern>
答案 0 :(得分:1)
转到您的模型并在使用部分添加:
use Backpack\CRUD\app\Models\Traits\CrudTrait;
并在模型主体部分添加:
use CrudTrait;
应该可以。
答案 1 :(得分:0)
评论自动添加CrudTrait,然后按照@OMR here的建议手动添加。大概没有必要,但是现在命令调用按常规顺序工作:
blueprint:build
backpack:build
CrudModelBackpackCommand.php(第75行):
// if it does not have CrudTrait, add the trait on the Model
$classDefinition = 'class '.$this->getNameInput().' extends';
// foreach ($file_array as $key => $line) {
// if (Str::contains($line, $classDefinition)) {
// if (Str::endsWith($line, '{')) {
// // add the trait on the next
// $position = $key + 1;
// } elseif ($file_array[$key + 1] == '{') {
// // add the trait on the next next line
// $position = $key + 2;
// }
// // keep in mind that the line number shown in IDEs is not
// // the same as the array index - arrays start counting from 0,
// // IDEs start counting from 1
// // add CrudTrait
// array_splice($file_array, $position, 0, ' use \\'.$this->crudTrait.';');
// // save the file
// $this->files->put($path, implode(PHP_EOL, $file_array));
// // let the user know what we've done
// $this->info('Model already exists! We just added CrudTrait on it.');
// return false;
// }
// }
$this->error('Model already exists! Could not add CrudTrait - please add manually.');
return false;
}
我可能已将某些文件移出了位置,但是我不确定是哪个文件...
此案也作为他们的github here上的一个错误打开。