mehdi-fathi/eloquent-filter

Target class [eloquentFilter] does not exist.

Nexulo opened this issue · 9 comments

Hello, unfortunately I can't get this extension to work. I tried a few months ago, but failed because of the same problem as now.

Error message:
Target class [eloquentFilter] does not exist.

I made all adjustments according to the instructions. Also in the app.php file I inserted both lines according to the instructions.
Can someone please help me?

Model:

<?php

namespace App;

use eloquentFilter\QueryFilter\ModelFilters\Filterable;
use Illuminate\Database\Eloquent\Model;
#use Illuminate\Database\Eloquent\Builder;

class Files extends Model
{
    use Filterable;

	public $timestamps = false;
	protected $fillable = ["user_id", "relative_path", "filename", "fileextension", "insert_time", "file_last_changed", "last_scan_touch", "last_analysed_metadata", "last_convert_run", "last_recognition_run", "probably_deleted"];


    /**
     * @var array
     */
    private static $whiteListFilter = ['*'];

Controller:

<?php

namespace App\Http\Controllers;

use App\Files;
use App\FileMetatags;
use App\FilesLocation;
use DateTime;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

class FileController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function indexJSON() {

        $filesFiltered = Files::filter();

        dd($filesFiltered);

@maisen20 Hello
you should read readme.md again. I guess you didn't add
'EloquentFilter' => eloquentFilter\Facade\EloquentFilter::class, in app.php and don't forget composer autoload after that.

Hello mehdi-fathi, thank you very much for your help.

I have added both additions to the app.php file. I also autoload composer.

Unfortunately it does not work.

The error message:

Illuminate\Contracts\Container\BindingResolutionException
Target class [eloquentFilter] does not exist.

My additions to the app.php file:

'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,

       [...]

        /*
         * Package Service Providers...
         */
        eloquentFilter\ServiceProvider::class,

/*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => [

        'EloquentFilter' => eloquentFilter\Facade\EloquentFilter::class,

@maisen20 Which version laravel are you using?

@mehdi-fathi
Laravel Framework 7.24.0

I have read that there are problems with version 8, but that does not concern me.

@maisen20 I've installed the eloquent filter in the laravel 7.x without any problem. Also, the eloquent filter tested by Github's action in all version laravel. I suggest reinstalling the eloquent filter and clear cache composer.

@mehdi-fathi

I saw that the package https://github.com/Tucker-Eric/EloquentFilter is installed, but I never installed it, as far as I know.

Now I have removed this package and I don't get an error message anymore, but I have to check if the filtering works.

@mehdi-fathi

Now it works. I'm sorry, but I was not aware that another package was installed. I really can't explain that.

Thanks a lot!

Just in-case any other person has this issue:
Ensure:

'providers' => [
  /*
   * Package Service Providers...
   */
    eloquentFilter\ServiceProvider::class
],

and this:

'alias' => [
  /*
   * Facade alias...
   */
    'EloquentFilter' => eloquentFilter\Facade\EloquentFilter::class,
],

And the run this ⚠(Very important):

php artisan optimize

This ensures the cached config.php is update

Hey, what about including php artisan optimize in the README.md?

I was facing this issue, and I solved it with this command. I don't think that others will look at the issues to find a solution.