Hey, guys.
I am having a problem trying to call a data field with a relationship using blade. I have followed the steps mentioned in the documentation (https://the-control-group.github.io/voyager/docs/v0.10/#core-concepts-bread-relationships) still with no luck. I did exactly as instructed, but on my 'posts' table.
In a page I have a blade @foreach that displays the post fields. All the fields output data as expected, except the post author. I am calling the field using {{ $posts->authorId()->name }} and I get the following error:
Undefined property: Illuminate\Database\Eloquent\Relations\BelongsTo::$name (View: /home/anderson/atom-projects/planeta-gundam/resources/views/blog/index.blade.php)
Am I doing something wrong? I'm using the latest version of Voyager (0.10.15) and Laravel 5.3. Thanks.

Please read the Laravel documentations about relationships.
{{ $post->authorId()->first()->name }}
I was way off track with this. I wanted to do this on my front end, not in my admin. After reading the documentation, I created two functions in my Post model:
public function author()
{
return $this->belongsTo(User::class);
}
public function category()
{
return $this->belongsTo(Category::class);
}
Then on my front end template I called {{ $post->author->name }} and... Voila! it worked.
I assumed that what the documentation showed would also work on the frontend, but its sole purpose is to make stuff come up in the dropdowns in the admin. Lesson learned. Thanks for your help.
i don't think you need to add the custom functions now you can $post->authorid->name simply now
tried but says
Trying to get property of non-object
This issue has been closed for 8 months now and was for a much older version. Please open your own issue if you're having trouble
I have this problem too, I am new in voyager 1.0 and laravel 5.5.*, I solved in this way
in web.php
Route::get('/posts', function () {
$posts = TCG\Voyager\Models\Post::all();
return view('posts', compact('posts'));
});
Route::get('post/{slug}', function($slug){
$post = TCG\Voyager\Models\Post::where('slug', '=', $slug)->firstOrFail();
return view('post', compact('post'));
});
and use in view
{{ $post->authorId()->first()->name }}
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
I was way off track with this. I wanted to do this on my front end, not in my admin. After reading the documentation, I created two functions in my Post model:
Then on my front end template I called {{ $post->author->name }} and... Voila! it worked.
I assumed that what the documentation showed would also work on the frontend, but its sole purpose is to make stuff come up in the dropdowns in the admin. Lesson learned. Thanks for your help.