【发布时间】:2021-09-01 08:29:26
【问题描述】:
我需要一点帮助。我还想将选项中的 $item->name 保存到名称列中的类别数据库中。感谢您的帮助。
我的刀片代码:
<label>Select a Category</label>
<select class="select2 form-control" for="cateId" wire:model.lazy="cateId">
<option value="">Select a Category</option>
@foreach ($categorylist as $item)
<option value="{{ $item->id }}">{{ $item->name }}</option>
@endforeach
</select>
我的 livewire 控制器:
public $name;
public function submit()
{
Category::create([
'name' => $this->$item->name,
]);
}
我的类别模型:
protected $table = "category";
protected $fillable = [
'name',
];
【问题讨论】:
-
这对我来说不太有意义,也许您可以更好地描述您的问题?您有一个来自
$categoryList的ID,它绑定到cateId属性。这意味着您可以从该属性中找到函数中的类别名称。使用$this->$item->name也没什么意义,因为它们在不同的地方。