mercredi 27 avril 2016

Laravel 5.1 retrieve multiple input value and insert to db

I have an input form named category that can have multiple value just like tags input form in stackoverflow when you asking a question
I want to get all input value from that form and insert it into category_service pivot table
I use $category = implode(",", Input::get('category')); to get the array value
And then i get Invalid argument supplied for foreach() error when try to insert it using this code:

foreach ($category as $category) {
    DB::insert('INSERT INTO category_service (category_id, service_id) VALUES (?,?)', array('$category', $service->id));
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire