mercredi 17 janvier 2018

Edit record validating single field in other table Laravel

I have four tables of the levels of my system (I am not sure if this relationship is well built), but basically I will only expose two with that and I will have reference for the other 3

 Users                                Docentes
 -id                                    - id
 -nivel_id (references nivel table)     - user_id (references users)
 -dni (unique)                          - sexo
 -password                              - other columns

to register first register in Users and then in Docentes , this part is solved in this question

Now what is causing me problems is to edit that record, I do not know how to validate in my formRequest the field dni if the parameter that happened id is from the teacher of the table Docentes->id

Controller , update

 public function update(DocenteRequest $request, $id)
 {
    $user = User::findOrFail($id);
    $user->update($request->except('nivel_id') + ['nivel_id' => 2]);
    $user->docente()->update($request->all());
    return redirect()->route('docente.index');
}

DocenteRequest

    case 'PATCH':
        {
            return [
                'dni' => 'required|digits:8|numeric|unique:users,dni,'.$this->docente,
                'especialidad' => 'required|min:3|max:60',
                'sexo' => 'required|not_in:0',
                'apellido_paterno' => 'required|min:2|max:80',
                'apellido_materno' => 'required|min:2|max:80',
                'nombre' => 'required|min:2|max:80',
                'telefono' => 'required|min:6|max:11',
                'direccion' => 'required|string',
            ];
        }



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

Aucun commentaire:

Enregistrer un commentaire