duanjuelu8874 2016-09-22 02:34
浏览 146
已采纳

在laravel 5.2中找不到replicate()方法

I am trying to replicate table row and its relationship.

but I am getting error message that replicate() does not exist,

enter image description here

I have seen on stackoverflow that many have used replicate() without any issue, but i am getting this error

my controller code

 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();

    $newshowtime=$movieshowtime->replicate();
    return $newshowtime;


}

Is there any namespace i have to use for using replicate() , I am unable to get solution from laravel website also.

help is appreciated.

  • 写回答

2条回答 默认 最新

  • dongyuan1970 2016-09-23 05:21
    关注

    This code worked perfectly for me

     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);
    
    
    
            }
        }
    
        return redirect()->back();
    
    
    }
    

    Any suggestions to improve this code will be appreciated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答