dimanche 6 mars 2016

How to save/delete database record based on checkbox selection?

I have @ 100 rows in a html table, with some ids/names. I want to let's say select 10 and save. In the database I will have 10 records now. After I deselect 3 from those 10 and select another 5, now I have 12.

The way I do it now is like this:

        DB::table('list_distributors')->where('listId', '=', $listId)->delete();

        $data = [];
        $distributors = $request->get('distributors',[]);

        foreach ($distributors as $key => $value) {
            $data[] = [
                'listId' => $listId,
                'distId' => $value
            ];
        }

        DB::table('list_distributors')->insert($data);

But....I don't think this is the best way. I need but I can't find a pro solution... Can someone give me some advice?

Thanks!



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

Aucun commentaire:

Enregistrer un commentaire