dimanche 27 décembre 2015

Fetching serialized data stored in database using laravel, while edit

I made form in which i have created fields for days of week, which i store in database as serialize. While I edit the form, and change days data does not get stored in database, instead it comes to error as

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

What can i do to save values to database?

here is my code:

Controller:

public function store(EventRequest $request)
{
    $checkbox = Input::get('days_of_week');
    $input = Request::all();
    $input['days_of_week'] = serialize(Input::get('days_of_week'));
    Event::create($input);

    return redirect('event');
}

public function edit($id)
{
    // get the event
    $event = Event::findOrFail($id);
    $s = Category::all()->where('parent_id','=','0');
    $days = array(
        'Monday' => 'Monday',
        'Tuesday' => 'Tuesday',
        'Wednesday' => 'Wednesday',
        'Thursday' => 'Thursday',
        'Friday' => 'Friday',
        'Saturday' => 'Saturday',
        'Sunday' => 'Sunday',
    );
    // show the edit form and pass the event
    return view('event.edit')->with('event', $event)->with('s',$s)->with('days',$days);
}

Edit.blade.php:

    <div class="dropdown">
    <a href="#">
        <input type="text" name="fname" class="hida" placeholder="select number of days"/>
        <p class="multiSel"></p>
    </a>
    <div class="mutliSelect">
        @foreach($days as $day)
            <ul>
                <li>
                    {!! Form::checkbox("days_of_week[]", $day, null) , $day !!}
                </li>
            </ul>
        @endforeach
    </div>
</div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire