Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iki's avatar
Level 3

One to many relationship problem

i have this tables

https://gyazo.com/9b498e266cf49e238d3b6b353af9a347

https://gyazo.com/7962b5074ecd97048207849642dddf8d

https://gyazo.com/faacdcf7b82f2cafcbf621dbd21d9f00

https://gyazo.com/d5933c54a64be52d4614052710071b5b

and thats my code

model AgentMeeting


public function meeting(){


        return $this->belongsto('App\MeetingType','meeting_type_id');
    }

Model MeetingType

public function agentmeeting(){

        return $this->hasMany('App\AgentMeeting');

    }
                                              
  <td>{{$data->meeting()->name }}</td>

and thats whai i get

https://gyazo.com/0aafcef9dab7ea5e18c85075dee72375

it shows wrong data and only shows three then it gives error trying to get property name of non object and tried optional() but it then gives me the last input as empty data , whats the wrong here , i feel thats its the foreign key

0 likes
1 reply
iki's avatar
iki
OP
Best Answer
Level 3

solved

Please or to participate in this conversation.