gpt4 book ai didi

laravel-5.3 - 如何获取 Backpack 使用的其中一个属性的值?

转载 作者:行者123 更新时间:2023-12-02 04:04:52 24 4
gpt4 key购买 nike

例如,我需要获取“id”值并使用它来搜索我的模型文章,但这个值 (id) 也出现在 URL 中:“/article/4/edit"和 "setColumns"参数中,我不知道如何获取它。

我需要你的帮助。这是我的示例代码:

ArticleCrudController.php

public function __construct()
{
parent::__construct();

$this->crud->setModel('App\Models\Article');
$this->crud->setRoute("admin/article");
$this->crud->setEntityNameStrings('article', 'articles');

$this->crud->setColumns(['id', 'title', 'text']);

// WHERE ARE YOU ID?!?!!!
$article = Article::findOrFail($id);
$pictures = $article->picture()->first()->name;

$this->crud->addFields([
[
'name' => 'title',
'label' => 'Title',
'type' => 'Text'
],
[
'name' => 'text',
'label' => 'Text',
'type' => 'ckeditor'
],
[ // Browse
'name' => 'image',
'label' => 'Article immage',
'type' => 'browse',
'value' => $pictures //Obviously without id don't work :'(
]

]);

}

最佳答案

您可以尝试重写 CrudController::edit 方法,将 id 作为第一个参数传递给该方法。

public function edit($id)
{
$articlePicture = Article::findOrFail($id)->picture()->first()->name;

$this->crud->addField([
'name' => 'image',
'value' => $articlePicture
]);

return parent::edit($id);
}

这可能是一个解决方案,但我不确定这是做你想做的事情的正确方法。

关于laravel-5.3 - 如何获取 Backpack 使用的其中一个属性的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39982977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com