Laravel 有没有办法在数据库中存储foreach值

Laravel 有没有办法在数据库中存储foreach值,laravel,laravel-5.7,Laravel,Laravel 5.7,我正在尝试使用controller在数据库中存储view-foreach值,在没有view-foreach的情况下,还有其他方法可以通过controller存储值吗 看法 在控制器中尝试此操作,并将记录作为数组获取。在视图中显示之前,脚本将检查记录并将其插入数据库。希望能有帮助 $data['ticket_details']='assign record'; //this goes to the view $ticket_details[]='assign record'; th

我正在尝试使用controller在数据库中存储view-foreach值,在没有view-foreach的情况下,还有其他方法可以通过controller存储值吗

看法


在控制器中尝试此操作,并将记录作为数组获取。在视图中显示之前,脚本将检查记录并将其插入数据库。希望能有帮助

    $data['ticket_details']='assign record'; //this goes to the view
    $ticket_details[]='assign record'; this goes to the controller

    foreach($ticket_details as $key=>$ticket_detailss)
    //checking if exacts record exists     
                   if(DB::table('table')->where('id',$ticket_detailss->ticket_id)->where('subject',$ticket_detailss->subject)->where('name',$ticket_detailss->name)->where('user_filter_id',$ticket_detailss->user_filter_id)->where('user_staff_id',$ticket_detailss->user_staff_id)->first())
                         {
                        //if record exists, do not insert
                        }else{
                           //if record do not exists, insert into db
                          $save =  DB::table('table')->insert([
                          'subject'             => $ticket_detailss->subjecte,
                          'name'          => $ticket_detailss->name,
                          'user_filter_id'        => $ticket_detailss->user_filter_id,
                          'user_staff_id'=> $ticket_detailss->user_staff_id,

                        ]);
                        }
                     }

return view('blade',$data);

检查这个问题,好的。它的抛出错误,因为该列需要信息,但没有插入任何内容。解决方案是使数据库中的列为null。所以即使没有数据,它也不会抛出错误。您想将刀片服务器中声明的foreach存储到dbyes我从其他数据库表中获取该foreach值,并将该值存储到另一个表列中
public function manager_send_messageChat(Request $request)
{

    $this - >validate($request, [

    'message' = >'required|string|max:255', 'ticket_id' = >'string|max:255',

    ]);

    foreach($ticket_details as $ticket_detailss) {

        $ticket_detailss['name'] = $ticket_detailss - >name;
        $ticket_detailss['user_filter_id'] = $ticket_detailss - >user_filter_id;
        $ticket_detailss['user_staff_id'] = $ticket_detailss - >user_staff_id;

        $input['message'] = $request - >message;
        $input['manager_staff_id'] = Auth::user() - >staff_id;
        $input['manager_filter_id'] = Auth::user() - >id;
        $input['manager_name'] = Auth::user() - >name;
        $input['reply_by'] = 'staff';
        $input['ticket_id'] = $request - >ticket_id;

        User_Ticket_Chat::create($input);

        return redirect('/ticket') - >with('success', ' THIS TICKET ASSIGNED FOR YOU .');
    }
}
    $data['ticket_details']='assign record'; //this goes to the view
    $ticket_details[]='assign record'; this goes to the controller

    foreach($ticket_details as $key=>$ticket_detailss)
    //checking if exacts record exists     
                   if(DB::table('table')->where('id',$ticket_detailss->ticket_id)->where('subject',$ticket_detailss->subject)->where('name',$ticket_detailss->name)->where('user_filter_id',$ticket_detailss->user_filter_id)->where('user_staff_id',$ticket_detailss->user_staff_id)->first())
                         {
                        //if record exists, do not insert
                        }else{
                           //if record do not exists, insert into db
                          $save =  DB::table('table')->insert([
                          'subject'             => $ticket_detailss->subjecte,
                          'name'          => $ticket_detailss->name,
                          'user_filter_id'        => $ticket_detailss->user_filter_id,
                          'user_staff_id'=> $ticket_detailss->user_staff_id,

                        ]);
                        }
                     }

return view('blade',$data);