BadMethodCallException
hsmyv opened this issue · 4 comments
"message": "Call to undefined method Illuminate\Database\Eloquent\Builder::like()",
"exception": "BadMethodCallException",
......
Post Controller:
public function likePost($id)
{
$user = User::where('id', auth()->user()->id);
$post = Post::find($id);
$user->like($post);
return response(['message' => 'Post Like successfully!']);
}
Post Model:
Hi @hsmyv,
This is not a issue about this package, you dont get the user correctly.
$user = User::where('id', auth()->user()->id)->first();
Also you can use:
$user = User::find(auth()->user()->id);
PD: You can change auth()->user()->id for auth()->id()
Hi @jdesousa1 ,
This is not a issue about this package, you dont get the user correctly.
$user = User::where('id', auth()->user()->id)->first();
Also you can use:
$user = User::find(auth()->user()->id);
PD: You can change auth()->user()->id for auth()->id()
They do same job. I think that issue is in the package didn't install completely
Hi @jdesousa1 ,
This is not a issue about this package, you dont get the user correctly.
$user = User::where('id', auth()->user()->id)->first();
Also you can use:
$user = User::find(auth()->user()->id);
PD: You can change auth()->user()->id for auth()->id()They do same job. I think that issue is in the package didn't install completely
Did you add the Liker (user) and Likeable (post) traits?
Hi @jdesousa1 ,
This is not a issue about this package, you dont get the user correctly.
$user = User::where('id', auth()->user()->id)->first();
Also you can use:
$user = User::find(auth()->user()->id);
PD: You can change auth()->user()->id for auth()->id()
OMGG. You are so awesome man! It is worked. I rewrite code:
POST Controller:
public function likePost($id)
{
$user = User::where('id', auth()->id())->first();
$post = Post::find($id);
$user->like($post);
return response(['message' => 'Post Like successfully!']);
}