simangae
1529
53
Laravel

Return Data from Database with vue

Posted 10 months 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.