I've got following LARAVEL self relationship on User model:
public function matchesSet(){
return $this->belongsToMany(self::class, 'matches', 'user_id', 'match_id')->withPivot('confirmed');
}
Then I run:
User::first()->matchesSet->where('pivot.confirmed', true)->where('name','LIKE', 'John')->count()
or
User::first()->matchesSet->where('pivot.confirmed', true)->where('name','John')->count()
and I get the expected result: "1" in this case.
BUT if I add % to the LIKE query, in any of this variants:
User::first()->matchesSet->where('pivot.confirmed', true)->where('name','LIKE', '%John%')->count()
User::first()->matchesSet->where('pivot.confirmed', true)->where('name','LIKE', '%{John}%')->count()
User::first()->matchesSet->where('pivot.confirmed', true)->where('name','LIKE', "%John%")->count()
User::first()->matchesSet->where('pivot.confirmed', true)->where('name','LIKE', "%{John}%")->count()
then I get wrong result, in all cases: "0".
What's wrong with my LIKE queries?
Thank you!