samedi 18 février 2017

How to make shortest code?

I use the following code to insert multi array to database:

foreach($request->category as $k => $v){
                $category[] = array(
                    "category_id" => $v,
                    "announcement_id" => $announcement->id
                );
            }

            AnnouncementCategory::insert($category);

So, input data is POST array $request->category. I need to refactoring this code



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2m7ZmzP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire