iverberk / larasearch

Searchable Eloquent Models
MIT License
225 stars 48 forks source link

Arg 2 to Illuminate\Foundation\Application::make() must be of the type array, object given #94

Open feenx opened 9 years ago

feenx commented 9 years ago
 [ErrorException]
  Argument 2 passed to Illuminate\Foundation\Application::make() must be of the type array, object given, called in
   /home/vagrant/code/g2anime/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 213 and de
  fined

I encountered this error when attempting to run php artisan larasearch:reindex --dir=app/Models but I didn't encounter any errors when running php artisan larasearch:paths --dir=app/Models. I looked at the files in question between Laravel v5.0 and v5.1 and didn't see any differences that could cause the issue and I have another app running Laravel v5.0 with no issues.

Any ideas @iverberk?

florentsorel commented 9 years ago

+1

feenx commented 9 years ago

Upon going through the error some more I've narrowed down the issue to this segment of code within SearchableTrait.php

public static function getProxy()
    {
        if (!static::$__es_proxy)
        {
            $instance = new static;

            if ($instance instanceof Model)
            {
                static::$__es_proxy = App::make('iverberk.larasearch.proxy', $instance);

                return static::$__es_proxy;
            } else
            {
                throw new \Exception("This trait can ony be used in Eloquent models.");
            }
        }

        return static::$__es_proxy;
    }

It seems the part static::$__es_proxy = App::make('iverberk.larasearch.proxy', $instance); is the problem. I don't know how this was done before though.

lmahesh5 commented 9 years ago

This was an old bug, since the owner is not responding at all, i have created a fork and fixed it. https://github.com/lmahesh5/larasearch Infact you can correct it in your package itself. Just replace that line " static::$__es_proxy = App::make('iverberk.larasearch.proxy', $instance); " with this line " static::$__es_proxy = new \Iverberk\Larasearch\Proxy($instance); " in SearchableTrait.php

prigal commented 9 years ago

@lmahesh5, I try using your fork with "repositories" in my composer without success because you make your correction in dev-master and not in L5 branch :)

@pfeiferchristopher, your fork is ok (L5 branch is used)

@lmahesh5 @pfeiferchristopher, I still have un bug when trying to reindex :

vagrant@homestead:~/Projets/app$ php artisan larasearch:reindex App\\Product --relations
---> Reindexing App\Product

  [ErrorException]                                                                                                                                                                         
  Argument 1 passed to Illuminate\Database\Eloquent\Builder::parseRelations() must be of the type array, null given, called in /home/vagrant/Projets/app/vendor/laravel/framework/s  
  rc/Illuminate/Database/Eloquent/Builder.php on line 752 and defined                                                                                                                      

Any idea ?

lmahesh5 commented 9 years ago

@pierrerigal If you are using a single table for indexing, then just "php artisan larasearch:reindex App\Models\index_model_name" is enough. But if you are using multiple tables (join) for indexing, then only that -- relations should be used, though i didnt tried it. My assumption based on the error it expects some parameters additionally for the --relations option (may be relative table names)

Bouhnosaure commented 9 years ago

I have the same error, i'm on Laravel 5.1

λ php artisan larasearch:reindex --relations --dir=App                                                                                                                                                             
---> Reindexing App\Equipment                                                                                                                                                                                      

  [ErrorException]                                                                                                                                                                                                 
  Argument 2 passed to Illuminate\Foundation\Application::make() must be of the type array, object given, called in C:\lamp\www\api-adv\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php o   
  n line 213 and defined                                                                                                                                                                                           
dairton commented 9 years ago

Hi, i've got the same problem. I'm on Laravel 5.1

php artisan larasearch:reindex App\\Dispensa --relations
---> Reindexing App\Dispensa

  [ErrorException]
  Argument 1 passed to Illuminate\Database\Eloquent\Builder::parseRelations() must be of the type array, null given, called in /var/www/html/contratos/vendor/laravel/framework/src/Illuminate/Database/Eloq
  uent/Builder.php on line 755 and defined

@pierrerigal, Did you figure it out? Thanks!

Edit: I got it. It was missing the --write-config option.

lasselehtinen commented 9 years ago

Having the same issue. Somebody wants to make a PR for this?

kJamesy commented 9 years ago

This is a nice package, however the author should really update it to Laravel 5.1 or merge the PRs. Anyone wanna submit their L5.1 fork to packagist, otherwise? Thanking you...

Oh, just using the fork for the time being. Composer is really helpful.

ghost commented 8 years ago

+1