Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Remove Column from Laravel Collection variable

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading