You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public function drivers()
{
return $this->belongsTo(Driver::class, 'id', 'user_id');
}
public function isDriverAvailable()
{
return $this->drivers();
}
and then the UserRepository (Repositories)
use Illuminate\Database\Query\Builder;
class UserRepository extends Repository
{
public function filterIsDriverAvailable(Builder $query, $method, $clauseOperator, $value, $in)
{
$query->whereIn('drivers.status', ['available']);
}
It returned this error when I tried to filter using postman "Type error: Argument 1 passed to Api\Users\Repositories\UserRepository::filterIsDriverAvailable() must be an instance of Illuminate\Database\Query\Builder, instance of Illuminate\Database\Eloquent\Builder given"
$this->belongsTo(Driver::class, 'id', 'user_id') <-- this one is Eloquent\Builder
The text was updated successfully, but these errors were encountered:
akito85
changed the title
Builder class in filter must be from Illuminate\Database\Query\Builder?
Filter function BUILDER expected Illuminate\Database\Query\Builder but Illuminate\Database\Eloquent\Builder given
Apr 18, 2017
I just found out the solution for this.
you should use Eloquent\Builder instead.
but you will get another error call to undefined something
if you are using belongsTo in the relation, you will get error call to undefined builder::getotherkey()
this is because of the laravel version. as far as I know genie, bruno, and larapi are using laravel 5.2 but in laravel 5.4 some of the function name has been renamed like getOtherKey() into getOwnerKey()
so just check out bruno in EloquentBuilderTrait (last function) rename it and use the new function name.
it will solve your issue
FYI: the function name has been renamed only since 5.4 so if you are using 5.1 - 5.3 I believe that you will get no problem
I have this function in my User (Models)
and then the UserRepository (Repositories)
It returned this error when I tried to filter using postman
"Type error: Argument 1 passed to Api\Users\Repositories\UserRepository::filterIsDriverAvailable() must be an instance of Illuminate\Database\Query\Builder, instance of Illuminate\Database\Eloquent\Builder given"
but
any ideas on how to resolve this?
The text was updated successfully, but these errors were encountered: