-1

I am trying to move values from temp table to main table after approval.

But, I don't have status, cancelled, and cancelled by columns in main table it's only available in the temp table. So, if I try to move all the fields from temp table to main table, it's showing error.

enter image description here

I am trying to move using the below codes.

public function approve(mpd_temp $mpd)
{

$result = mpd::insert($mpd->toArray());

if ($result) {
    mpd_temp::where('sno', $mpd->sno)->delete();
    toast('MPD Successfully Approved', 'success');
}

}

I have tried

$mpd->forget('status');
$mpd->forget('cancelled_at');
$mpd->forget('cancelledby');

But it's showing enter image description here

Is there any best way to move columns from temp table to main table and delete from temp after insert?

Lokesh M
  • 25
  • 6

2 Answers2

2

You must unset() the key you want to remove. In your case you must do

unset($mpd->cancelledby);

And it should be removed from the collection.

Laralex
  • 125
  • 8
2

You can use except function on your collection:

$mpd->except(['status', 'cancelled_at', 'cancelledby']);
Vahid
  • 940
  • 4
  • 14