Php 拉雷维尔8号及;具有值数组而不是单个值的laravel livewire简单CRUD
当我们制作简单的积垢应用程序时。 在我们的火线控制器中采用编辑方法Php 拉雷维尔8号及;具有值数组而不是单个值的laravel livewire简单CRUD,php,laravel,Php,Laravel,当我们制作简单的积垢应用程序时。 在我们的火线控制器中采用编辑方法 public function rEdit() { $this->data = auth()->user()->product()->where('id',$this->pid)->first() } 表字段为“id、名称、价格等” 然后在带电钢丝刀片中,我们可以得到这个值 <x-jet-input id="name" type=&
public function rEdit()
{
$this->data = auth()->user()->product()->where('id',$this->pid)->first()
}
表字段为“id、名称、价格等”
然后在带电钢丝刀片中,我们可以得到这个值
<x-jet-input id="name" type="text" class="mt-1 block w-full" wire:model.defer="data.name" />
若我在规则中添加名称,它将在blade中显示值,若我删除它,它将不显示值。
表中有100个字段,有些是必需的,有些不是。在Livewire组件上定义一个
user
属性,然后将刀片组件中的字段连接到用户的属性。然后,只需在user
对象上调用save
class UserComponent extends Component
{
public $user;
public function mount()
{
$this->user = auth()->user();
}
public function save()
{
$this->user()->save();
}
}
您需要为要绑定到的模型上的每个属性定义验证规则:
注意:要使其工作,您在$rules
要绑定到的任何模型属性的属性。否则
将抛出错误
你好,谢谢你的更新。我已经尝试了我的查询作为贝娄,我得到贝娄错误你好,谢谢你的更新。我尝试了下面的查询$data=auth()->user()->product()->where('id',$this->editid);我得到了下面的错误,在blade htmlspecialchars()中,如果我使用下面的查询$data=auth()->user()->product()->where('id',$this->editid)->first(),则参数1应该是字符串,object gived;没有错误,但bellow没有显示任何值。我让它工作,我需要在验证规则中定义它们。但是,如果变量不在公共函数规则()中,为什么它不工作({return[
class UserComponent extends Component
{
public $user;
public function mount()
{
$this->user = auth()->user();
}
public function save()
{
$this->user()->save();
}
}
<x-jet-input id="name" type="text" class="mt-1 block w-full" wire:model.defer="user.name" />
<x-jet-input id="email" type="email" class="mt-1 block w-full" wire:model.defer="user.email" />