Support the ongoing development of Laravel.io →
Configuration Database Views
Last updated 2 years ago.
0

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!

Last updated 8 years ago.
0

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 ...

0

Sign in to participate in this thread!

Eventy

Your banner here too?

yolita15 yolita15 Joined 16 Feb 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.