Closed JamieCee20 closed 2 years ago
Plz show me the controller code.
JamieCee20 notifications@github.comδΊ2020εΉ΄7ζ30ζ₯ ε¨εδΈε11:04ειοΌ
On my blade page I have {{ $post->likes()->count() }} to display the number of current likes however when I refresh the page I get the error: Method Illuminate\Database\Eloquent\Collection::likes does not exist.
To my understanding Im not using that so unsure why it wont find the function im looking for.
Any help would be appreciated.
Jamie
β You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/overtrue/laravel-like/issues/28, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALHOYEBQTS6OQ3S6RQM2YDR6GDZVANCNFSM4PN6SM2Q .
/**
* Display the specified resource.
*
* @param \App\Verified $verified
* @return \Illuminate\Http\Response
*/
public function show(Verified $verified)
{
$user = User::find($verified->user_id);
return view('verifieds.show', compact('user','verified'));
}
This is in my post Controller
So, $post is undefined?
JamieCee20 notifications@github.comδΊ2020εΉ΄7ζ31ζ₯ ε¨δΊδΈε1:06ειοΌ
/**
- Display the specified resource.
- @param \App\Verified $verified
- @return \Illuminate\Http\Response */ public function show(Verified $verified) { $user = User::find($verified->user_id); return view('verifieds.show', compact('user','verified')); }
This is in my post Controller
β You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/overtrue/laravel-like/issues/28#issuecomment-666529457, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALHOYG536SLSZ74K7E3ZC3R6GSAHANCNFSM4PN6SM2Q .
No I have it as $verified->likers() - >count()
Plz, explain where is the $post
defined? paste the controller code and blade template code.
So Due to the way my project pans out, $verified is my post. This is my controller
public function show(Verified $verified)
{
$user = User::find($verified->user_id);
return view('verifieds.show', compact('user','verified'));
}
And my blade was like this:
a class="likeButton" href=" $user->toggleLike($verified) "> i class="fas fa-thumbs-up mr-2">
Hi, @JamieCee20, I read your code, this error is impossible because $verified
will always be an instance of Verified
. So please double check your logic to see if there is a variable overwrite.
Verified is still posts and doesnt overrun anywhere. I have Post which is user posts but verified is the same functionality just for verified Users, (May be a less complicated scenario but im still very new to laravel).
So surely if I set my controller to $post = Verified::find({id}) then it will still be the same outcome?
/**
* Display the specified resource.
*
* @param \App\Verified $verified
* @return \Illuminate\Http\Response
*/
public function show(Verified $verified)
{
$user = User::find($verified->user_id);
$likes = $user->likes()->with('likeable')->paginate(20);
return view('verifieds.show', compact('user','verified', 'likes'));
}
This is my controller, verifieds is just a different post so imagine all $verified is $post.
My show.blade.php has this
@foreach($likes as $Like)
{{$like->likeable}}
@endforeach
to display my information.
and the error I get is Class name must be a valid object or a string
On my blade page I have {{ $post->likes()->count() }} to display the number of current likes however when I refresh the page I get the error: Method Illuminate\Database\Eloquent\Collection::likes does not exist.
To my understanding Im not using that so unsure why it wont find the function im looking for.
Any help would be appreciated.
Jamie