I am creating a code by which i can replicate the multiple rows of table and its related tables.
I am able to replicate parent table successfully, but while replicating the contents of child table it is modifying the values which i am unable to figure it out.
my controller code is
public function copyshowtime($cinema_id,$show_date)
{
$date=new Carbon($show_date);
$current_show_date=$date->format('Y-m-d');
$next_show_date=$date->addDay()->format('Y-m-d');
$movieshowtime=Movies_showtimes::with('showdata')->where([['cinema_id','=',$cinema_id],['show_date','=',$current_show_date]])->get();
foreach ($movieshowtime as $item)
{
$item->show_date=$next_show_date;
$item->show_id=NULL;
$newshowtime=$item->replicate();
$newshowtime->push();
foreach ($item->showdata as $sd)
{
$newshowdata = array(
'showdata_id' => NULL,
'show_id'=>$newshowtime->id,
'category_id'=>$sd->category_id,
'showdata_category'=>$sd->showdata_category,
'showdata_rate'=>$sd->showdata_rate
);
// print_r($newshowdata);
Movies_showdata::create($newshowdata);
}
}
}
When I am printing the complete array its showing proper data which i am trying to insert ,check below
But after inserting it into table I see this data in table, the values of show_id and showdata_rate is getting zero value and other columns getting correct data inserted.
I am unable to figure out this problem as I am nowhere changing the data to zero before inserting it into table.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire