mercredi 30 décembre 2015

Editing drop-down doesn't fetch value

I have created a drop-down for categories and subcategory. It works fine when i submit the form, but when I edit the form, category field does not come with refilled data from the database, category drop-down come like it show in create form.

here is my edit:

    <div class="form-group">
    {!! Form::label('category','Category:') !!}
    <select name="category" id="category" class="form-control input-sm">
        @foreach($s as $k)
            <option value="{{ $k['id'] }}">{{ $k['name'] }}</option>
        @endforeach
    </select>
</div>

<div class="form-group">
    {!! Form::label('subcategory','Subcategory:') !!}
    <select name="subcategory" id="subcategory" class="form-control input-sm">
        <option value=""></option>
    </select>
</div>

Controller:

    public function edit($id)
{
    // get the event
    $event = Event::findOrFail($id);
    $s = Category::all()->where('parent_id','=','0');
    $r = Event::all();
    $daysOfWeek = unserialize(Event::find($id)->days_of_week);
    // show the edit form and pass the event
    return view('event.edit',compact('event','s','r','daysOfWeek'));}

I haven't used relations for the dropdown, I have used jquery and ajax to select subcategory after I select category. What can i do to get the value stored in database when I do edit form?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire