Got Problem in Relation Table Column

So, i want to show the author name with this relation, but in the table the name of the author is not show. Need help
No description
No description
No description
No description
Solution:
if you changed the relationship name to author_model then use author_model.name in your table
Jump to solution
11 Replies
Tieme
Tieme4mo ago
What will show if u only use author without the .name?
вєя.
вєя.4mo ago
just author's id
🤖transistor🤖
seems to me that your relationship to authors is not right in your Discussion model. The key should be your local key for authors, which seems to be author
вєя.
вєя.4mo ago
is that an absolute problem, or there is another possibility that causing this problem? because i tried to change the relation from author to authors its make 500 error code
🤖transistor🤖
I'm sorry if it wasn't clear, this is what I think your belongsTo relation should look like:
public function author(): BelongsTo
{
return $this->belongsTo(Member::class, 'author');
}
public function author(): BelongsTo
{
return $this->belongsTo(Member::class, 'author');
}
then you should be able to use author.name assuming in your members table your primary key is id
вєя.
вєя.4mo ago
in relation manager it's fixed. but, in the table it gives me error Undefined property: App\Models\Discussion::$author yes it is
🤖transistor🤖
ok, it looks like it's confusing the author property (which is the author id, right?) and the author relationship. try changing your relation to something different, like public function author_model(): BelongsTo or anything different from author and the use that as the relationship name.
вєя.
вєя.4mo ago
and its still like the beginning, author.name is not showing anything in the table
Solution
🤖transistor🤖
if you changed the relationship name to author_model then use author_model.name in your table
вєя.
вєя.4mo ago
oh gosh, i didn't think of it cause it's almost morning in my country and quite tired with this problem 😂, thank you so much!
🤖transistor🤖
happy to help, and get some sleep! 😉