mardi 22 septembre 2020

Laravel Multiple Select Old Value

i'm added multiple select box using bootstrap-select in create form everything goes very well but I've a problem in edit form .

I tried many way to get the old selected value but nothing works

Blade:

                                        <select class="selectpicker" name="students[]" data-style="select-with-transition" data-live-search="true" multiple title="Choose City" data-size="7">
                                        <option disabled> Multiple Options</option>
                                        @foreach($students as $student)
                                            <option value="" > </option>
                                        @endforeach
                                    </select>

Edit function:

 public function edit(Course $course)
{
    $students=Student::all();
    return view('course.edit',compact('course','students'));
}

Store Function:

public function store(Request $request)
{
    $request->validate([
        'name' => 'required',
    ]);
    $course = new Course;
    $course->name = $request->name;
    $course->teacher_id = $request->teacher_id;

    $course->save();
    $course->students()->sync($request->students);

    return redirect()->route('courses.index')
        ->with('success','Course created successfully.');
}

any idea to do this ??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire