且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 4:复制到表

更新时间:2023-02-03 16:11:07

我解决了当您获取mysql行的副本时,您将所有json字符串都包含在内,因此您需要先使用 json_decode 函数对其进行解码再次将其添加到数据库中,因此如果有人遇到相同的问题,这是解决方案:)

I solved it when u get replicate of mysql row you get all inside json string so u need to decode it with json_decode function before adding it to database again so here is solution if someone has same problem :)

public function getClone($id) {

    $item = Data::find($id);
    $clone = $item->replicate();
    unset($clone['created_at'],$clone['updated_at']);

      $data = json_decode($clone, true);
      Product::create($data);

    return Redirect::to('admin/content')
        ->with('message', 'Clone Created!!');

}