【发布时间】:2020-04-13 14:03:38
【问题描述】:
我有一个 Laravel 代码,用于将数据插入表中,但我想根据插入项目的详细信息更新另一个表的内容;下面是我的控制器代码
public function docadd(Request $request){
$doc=new documents();
$doc->claim_id=request('id');
$doc->file_name=request('new');
$doc->cat=request('new');
$doc->type='needed';
$doc->description='needed';
$doc->save();
$id=$doc->claim_id;
$nm=$doc->file_name;
$dc=options::where('claim_id', $id)
->get();
$ed=$dc[0][$nm];
dd($dc[0]->$ed); //this dd returns "Doc2"
$dc->$ed=''; i want it to update the content of the table column with the column with
name of the dd value
$dc->save();
return redirect()->back();
}
请问我真的需要这方面的帮助
【问题讨论】:
-
现在有什么问题?你能再解释一下吗?
-
问题是它没有更新第二张表
-
我希望它转到表选项并获取具有 $ed=$dc[0][$nm]; 返回的名称的名称的列并将其值设置为空
-
如果您知道如何使用 Eloquent 模型,请查看这里:stackoverflow.com/questions/36999557/…
-
方法 Illuminate\Database\Eloquent\Collection::update 不存在。这是我尝试更新时遇到的错误