小编mer*_*ish的帖子

多选的Laravel验证

我正在制作一个多选表单元素,用于更新学校和专业数据透视表school_specialty.问题是,当我只更改多项选择而不是其他输入或textareas时,我无法监听模型事件,因此我无法同步school_specialty表.但是当我填写任何其他输入时,它的工作完美无缺.这是我从刀片中选择的多项选择:

{{Form::select('specialties[]', $specialties_data, $school->specialties, array('multiple' => 'true', 'id' => 'multi-select'))}}
Run Code Online (Sandbox Code Playgroud)

这是我的更新方法school controller:

public function update($id)
{
    $data = Input::only('name', 'type_id', 'description', 'info_specialties', 'contacts', 'specialties', 'financing_id', 'district_id', 'city_id');

    $school = School::find($id);
    $school->name = $data['name'];
    $school->type_id = $data['type_id'];
    $school->description = $data['description'];
    $school->info_specialties = $data['info_specialties'];
    $school->contacts = $data['contacts'];
    $school->cover_photo = Input::file('cover_photo');
    $school->set_specialties = $data['specialties'];
    $school->financing_id = $data['financing_id'];
    $school->set_district_id = $data['district_id'];
    $school->city_id = $data['city_id'];

    try {
        $school->save();
    } catch (ValidationException $errors) {
        return Redirect::route('admin.schools.edit', array($id))
            ->withErrors($errors->getErrors())
            ->withInput();
    } …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-validation

5
推荐指数
1
解决办法
1749
查看次数

标签 统计

laravel ×1

laravel-validation ×1

php ×1