PivotTable with additional field Eloquent Laravel 5.6 Mass Assigment Protection

0

when using pivot tables with additional fields, it does not allow me to create the record since I must declare it as fillable ... how could I declare the additional field as fillable?

Suppose we have the Student table and the Course table and a pivot table Student_Course

Table: Curso_Estudiante
----------------------------------------
| curso_id | estudiante_id | descripcion

course_id and student_id are added without problem but the field description I can not attach () since I must declare it as fillable somewhere

    
asked by kevin au tam 17.06.2018 в 00:50
source

1 answer

1

Right now I would not know if it's possible to assign a fillable to the pivot fields, but a simple solution and what I use would be something like this.

$estudiante = Estudiante::create($estudianteData);
$curso = Curso::create($cursoData);
$estudiante->curso()->attach($curso->id , ['descripcion' => $request->descripcion]);
    
answered by 17.06.2018 / 01:11
source