fadion / Bouncy

Map Elasticsearch results to Eloquent models
MIT License
71 stars 26 forks source link

Laravel 5 Support #1

Closed stevepop closed 9 years ago

stevepop commented 9 years ago

Thanks for your efforts to make querying Elasticsearch using Laravel a breeze. Any plans to port this to Laravel 5 support soon?

fadion commented 9 years ago

Added a l5 branch with composer requirements for Laravel 5 and will test it in the following days with an Elastic setup. Hopefully there won't be any problems and if you want to test it right now, require it in composer using:

"fadion/bouncy": "dev-l5"

stevepop commented 9 years ago

Cool! I will test it right away and feed you back. Thanks!

stevepop commented 9 years ago

There is a problem with the reference to $this->package('fadion/bouncy'); in the boot() method of the BouncyServiceProvider. Call to php artisan creates the following error;

'BadMethodCallException' with message 'Call to undefined method [package]' in /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:226 Stack trace:

0 /Users/steve/devapps/AfgosL5/vendor/fadion/bouncy/src/Fadion/Bouncy/BouncyServiceProvider.php(23): Illuminate\Support\ServiceProvider->__call('package', Array)

1 /Users/steve/devapps/AfgosL5/vendor/fadion/bouncy/src/Fadion/Bouncy/BouncyServiceProvider.php(23): Fadion\Bouncy\BouncyServiceProvider->package('fadion/bouncy')

2 [internal function]: Fadion\Bouncy\BouncyServiceProvider->boot()

3 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Container/Container.php(523): call_user_func_array(Array, Array)

4 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(624): Illuminate\Container\Container->call(Array)

5 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(606): Illuminate\Foundation\Application->bootProvider(Object(Fadion\Bouncy\BouncyServiceProvider))

6 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation{closure}(Object(Fadion\Bouncy\BouncyServiceProvider), 20)

7 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(607): array_walk(Array, Object(Closure))

8 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(15): Illuminate\Foundation\Application->boot()

9 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(158): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))

10 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(180): Illuminate\Foundation\Application->bootstrapWith(Array)

11 /Users/steve/devapps/AfgosL5/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(89): Illuminate\Foundation\Console\Kernel->bootstrap()

12 /Users/steve/devapps/AfgosL5/artisan(34): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

13 {main}

Steve

fadion commented 9 years ago

Unfortunately Laravel 5 has changed a lot in package development. I will investigate on a solution.

fadion commented 9 years ago

Updated the l5 branch with the recent changes to Laravel 5 service providers. The provider and the facade worked correctly, but it needs some setup to have a running elastic search server with indexes and all of that. I'd be grateful if you can give it a test run.

You'll need to run a composer update and artisan vendor:publish to publish the config files.

stevepop commented 9 years ago

Hi, I gave it a go tonight and I did get past the artisan vendor:publish. However, the next issue now is that the BouncyTrait is unable to obtain the Elasticsearch configuration. This results in the following error; DICBuilder.php line 71 at DICBuilder->construct(array(array('host' => 'localhost', 'port' => '9200')), null) in Client.php line 1412 at Client->setParams(null) in Client.php line 84 at Client->construct(null) in BouncyTrait.php line 563 at Members->getElasticClient() in BouncyTrait.php line 42

You can see that it is unable to read the elasticsearch config parameters. I traced the problem to line 563 return new ElasticSearch(Config::get('bouncy::elasticsearch')); When I dumped Config::get('bouncy::elasticsearch') it returned an array of my elasticsearch configuration. However when I dumped Config::get('bouncy::elasticsearch') it returned null. The Elasticsearch client needs this to work.

fadion commented 9 years ago

You're right! L5 removed config namespaces. Updated BouncyCollectionTrait and BouncyTrait and my dumps are returning correct configuration options. Please give it another go. Don't forget composer update.

stevepop commented 9 years ago

:+1: It works now. Glad I helped to sort this out. Off to bed! :)

fadion commented 9 years ago

Glad to hear and thanks for the help. I'm closing the issue! If you find any other problem or Laravel 5 breaks something in your app, please let me know.