Meysam Saberi Meysam Saberi - 1 year ago 152
PHP Question

checkbox to mysql in laravel 5.2

how to save checkbox value to database ?

my view code:

<input type="checkbox" name="checkbox" id={{$cat->id}} value={{$cat->id}}>

my controller code:

public function submitArticle(){
$article = new Post();
$article->title= Input::get('title');
$article->body= Input::get('body');
$article->cat = Input::get('checkbox');
$articleId = $article->id;
return $articleId;


use this code

<input type="checkbox" name="checkbox[]" id={{$cat->id}} value={{$cat->id}}>

and in controller

        $relationCategory = $checkbox;
        foreach ($relationCategory as $relCat){
            $rel = new Relationship();
            $rel->post_id = $articleId;
            $rel->cat_id = $relCat;