Support the ongoing development of →
Eloquent Laravel Database
Last updated 9 months ago.

First of all, before posting any thread please see the preview of the thread, as it's hard to find the problem. Solution: You need to eager load the relationship and get the data from the relationship attribute and not the id.

$rapports = Rapport::with('Rapport')->all();

and in your view you can access it like


One more suggestion that i want to give you is that, you should inverse the names of the relationship functions.


Thank you. I will try. where should I put this code you wrote

$rapports = Rapport::with('Rapport')->all();

Last updated by @maccladder 10 months ago.

i did and now i have this error

Call to undefined method Illuminate\Database\Eloquent\Builder::all()


try to use get() method instead of all()


Here is the error i get now with the get() method

ErrorException Attempt to read property "nom" on null (View: C:\wamp64\www\SET\resources\views\rapport\index.blade.php)


You have to define a custom value if the relationship id is not found on the target model like:

return $this->belongsTo(Agent::class)->withDefault([

Hope your code works now :)


Sign in to participate in this thread!

Full Stack Europe

Your banner here too?


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

Your logo here?

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

© 2023 - All rights reserved.