Hi Yolita,
It looks like inside of your postIndex method, you're creating your new ClassSubject called $rule with the following credentials:
$rule = ClassSubject::create([
'class_id'=> $request->get('class_id'),
'subject_id'=> $request->get('subject_id'),
'teacher_id'=> $request->get('teacher_id'),
]);
Then, inside of your view, you're trying to access $rule->user->full_name.
When you create the new rule in postIndex, you are only setting class_id, subject_id, and teacher_id, but never the user_id field. So, when your view tries to access $rule->user, it's returning null, and throwing the exception.
When you create the new rule object, add in the user_id field when you call create. Something like this:
$rule = ClassSubject::create([
'class_id'=> $request->get('class_id'),
'subject_id'=> $request->get('subject_id'),
'user_id' => /* Put User ID here (Auth::user()->id maybe?) */,
'teacher_id'=> $request->get('teacher_id'),
]);
I hope this helps!
Unfortunately no, because my "teacher_id" its from the User table. The problem is with these two:<td>{{ $rule->user->full_name }}</td> ; <td>{{ $rule->clas->name}}</td> because if I call them like this: <td>{{ $rule->teacher_id }}</td> and <td>{{ $rule->class_id}}</td> my page is displayed but I see only the IDs ...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.