laravel-admin
laravel-admin copied to clipboard
hasMany表单值为空
- Laravel Version: 8.83.0
- PHP Version: 8.1.3 or 7.4.27
- Laravel-admin: 2.0.0 Beta 5
Description:
hasMany表单提交以后的url ,desc 两个字段都为空
{
"_id": 5,
"text": "fds",
"images": [
{
"id": 4,
"article_id": 5,
"created_at": "2022-02-22T09:56:21.000000Z",
"updated_at": "2022-02-22T09:56:21.000000Z",
"url": null,
"desc": null,
}
],
},
Steps To Reproduce:
form代码
class ArticleController extends AdminController
{
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new Article());
$form->textarea('text', __('Text'))->required();
// $form->multipleImage('imgs')->sortable();
$form->hasMany("images", function (Form\NestedForm $form1) {
$form1->image("url");
$form1->text("desc");
});
return $form;
}
}
models 代码
class Article extends Model
{
use HasFactory;
public $fillable = ["*"];
public function images()
{
return $this->hasMany(Image::class, "article_id", "id");
}
public function toArray()
{
return [
"_id" => $this->id,
"text" => $this->text,
"images" => $this->images,
];
}
}
class Image extends Model
{
use HasFactory;
protected $fillable = ["*"];
}
加上belongsTo
關聯會有效嗎
DOC
class Image extends Model
{
use HasFactory;
protected $fillable = ["*"];
public function article()
{
return $this->belongsTo(Article::class, 'article_id');
}
}