I have a table 2 students and companies, the relationship is A student can work in many companies and a company can have many students consequently results in a pivot table student_business This pivot table has more independent additional data, when doing the insert in the table it works but how can I go through or visualize the data in this table?
My student model
class Alumno extends Model {
public function empresas()
{
return $this->belongsToMany(Empresa::class)->withPivot('fechaIncio',
'fechaConclusion','tipoSupervisor','supervisorNombre','fechaReconocimiento');
}
}
My business model
class Empresa extends Model{
public function alumnos()
{
return $this->belongsToMany(Alumno::class)->withPivot('fechaIncio','fechaConclusion',
'tipoSupervisor','supervisorNombre','fechaReconocimiento');
}
}
I try to do so by accessing a data as follows:
$alumno = App\Alumno::findOrFail(1);
return $alumno->empresa->pivot->fechaIncio;
but generates the following error
Trying to get property of non-object