简体   繁体   中英

How to update one table from two different pages in laravel

I have one table name files Now I have two types of files, one file purchase and second file sale but I use only one table. I am using laravel resource controller

my table files First i insert filepurchase data and store filesale value null [![enter image description here]

   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'));
  }

This is working fine.I want that when i click on sale button i insert file sale record against filepurchase with same id, and update null fields [![enter image description here]

There are various ways to complete that task , you only need record id eg:

 $table = Table::where('id', $id)->first();
 //Update record details
  $table->save();

OR

 Table::where('id', $id)->update([ 'index' => 'value' ]);   //need update details array

OR

 $table= Table::firstOrCreate(['id' => $id]);

OR

// Retrieve the Table the attributes, or instantiate a new instance...
 $table= Table::firstOrNew(['id' => $id]);

OR

 $table = Table::find($id);

then

 $table->save();

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM