Search code examples
laravelsearcheloquentadvanced-search

Simple use of Fouladgar's Eloquent Builder class return error "it is not an interface"


I am having a problem creating a simple filter to use the Eloquent Builder class. Returns me the error

App\EloquentFilters\Property\RoomsFilter cannot implement Fouladgar\EloquentBuilder\Support\Foundation\Contracts\Filter - it is not an interface

basically copied and pasting from how to get started

<?php
namespace App\EloquentFilters\Property;
use Fouladgar\EloquentBuilder\Support\Foundation\Contracts\Filter;
use Illuminate\Database\Eloquent\Builder;
class RoomsFilter implements Filter
{
    public function apply(Builder $builder, $value): Builder
    {
        return $builder->where('rooms', $value);
    }
}

Thanks guys for the help


Solution

  • You need to extend it, not implement it, as the error is saying.

    Change:

     class RoomsFilter implements Filter
    { }
    

    to

    class RoomsFilter extends Filter
    { }
    

    From the gitHub repo:

    Writing a filter is simple. Define a class that extends the Fouladgar\EloquentBuilder\Support\Foundation\Contracts\Filter abstract class. This class requires you to implement one method: apply.