我有一个表名文件 现在我有两种类型的文件,一种是购买文件,另一种是销售文件,但我只使用一张表。 我正在使用 laravel 资源 Controller
我的表格文件 首先我插入 filepurchase 数据并存储 filesale 值 null [![在此处输入图片描述]
public function store(Request $request, File $file)
{
$file->p_name = $request->p_name;
$file->p_co = $request->p_co;
$file->type_of_file = $request->type_of_file;
$file->file_status = $request->file_status;
$file->save();
// $arr['file']=File::all();
// $p=$file->p_price;
$data = [
$file->id,
$file->p_price,
];
return view('filetransaction.create',compact('data'));
}
这工作正常。我希望当我点击销售按钮时,我针对具有相同 ID 的文件购买插入文件销售记录,并更新空字段 [![在此处输入图片描述]
最佳答案
有多种方法可以完成该任务,您只需要记录 id 例如:
$table = Table::where('id', $id)->first();
//Update record details
$table->save();
或
Table::where('id', $id)->update([ 'index' => 'value' ]); //need update details array
或
$table= Table::firstOrCreate(['id' => $id]);
或
// Retrieve the Table the attributes, or instantiate a new instance...
$table= Table::firstOrNew(['id' => $id]);
或
$table = Table::find($id);
然后
$table->save();
希望这对您有所帮助。
关于php - 如何从 laravel 中的两个不同页面更新一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53717882/