my model
public function semesters(): BelongsToMany
{
return $this->belongsToMany(Semester::class)
->orderBy('name', 'desc');
}
my controller code
$semesters = Auth::guard('student')->user()->semesters;
my blade code is
{{ dd($semesters->name) }}
and the error is
Property [name] does not exist on this collection instance.
my expectation is to get singal semester name in blade
2
Answers
the another way:
**this is very simpale i also get idea from another stackovreflow question and also working for me **
The error you’re facing is due to the issue you’re not referring to the correct data. You can do it by doing something like this:
and then you can use
semesterName
to render the name on frontend. The code will fetch the first result and then get the name from the result. Hope this helps.