Return Data from Database with vue

Posted 1 month ago by simangae

Hi, I have two tables that has one to one relationship, when I try to access data from 2nd table, I get the "TypeError: Cannot read property 'bio' of null" .

Here my controller

return User::with('profile')->latest()->get();

RelationShip

public function profile(){ return $this->hasOne('App\StudentInfo'); }

Axios

axios.get("api/user").then(({ data }) => (this.users = data));

Table

{{ user.name }} {{ user.email }} {{ user.phone }} {{ user.photo }} {{ user.profile.bio}} //This gives me error when I remove It's working fine
                   <td>
                       <a href="">
                            <i class="material-icons">mode_edit</i>
                       </a>
                       <a href="">
                            <i class="material-icons">delete</i>
                       </a>
                   </td>

               </tr>

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.