lundi 27 mars 2017

QueryException in Connection.php line 647:

I'm trying to save checkboxes. I should be able to select one or mutliple. At the moment I'm getting this error

QueryException in Connection.php line 647: Array to string conversion (SQL: insert into seo (url, meta_title, meta_description, keywords, robot, updated_at, created_at) values (ff, ff, ff, ff, noindex, 2017-03-27 08:59:54, 2017-03-27 08:59:54))

Here is my create.blade.php

<div class="robots">
    {!! Form::label('noindex', 'noindex') !!}
    {!! Form::checkbox('robot[]', 'noindex') !!}

    {!! Form::label('follow', 'follow') !!}
    {!! Form::checkbox('robot[]', 'follow') !!}
</div>

my method in my seo controller

public function create()
{
    //Gets all the seo that are in the database
    $seos = Seo::with('menu')->get();
    //Lists the title of the seo
    $menu_options = Menu::pluck('title', 'id');
    return view('seo::admin.create', compact('seos'))->with('menu_options', $menu_options);
}

public function store()
{
    //Gets all the input in the fields in the form
    $input = Input::all();

    //Checks the input fields against the validation rules in the Seo model
    $validation = Validator::make($input, Seo::$rules);

    //If the validation fails the a message will pop up saying that there was validation errors
    if($validation->fails()){
        return redirect()->route('seo.create')
            ->withInput()
            ->withErrors($validation)
            ->with('message', 'There were validation errors');
    }

    //If the validation passes then it gets saved to the database
    if($validation->passes()){
        $seos = new Seo();

        //Gets the menu_id
        $menuId = (array) array_get($input, 'menu_id');
        //Saves the input to the database
        $seos->fill($input)->save();
        //Syncs the menu function in the Seo model to save the menu ID in menu_seo
        $seos->menu()->sync($menuId);

        $seos = Seo::all();
        return view('seo::admin.index', compact('seos'));
    }
}



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

Aucun commentaire:

Enregistrer un commentaire