Skip to content

Commit

Permalink
fix laravel scout non resolved class
Browse files Browse the repository at this point in the history
  • Loading branch information
basemkhirat committed Feb 19, 2017
1 parent b9f8ceb commit da38796
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.

## [0.8.2] - 2017-02-19

### Added
### Fixed
- fix pagination for non-laravel apps.

## [0.8.1] - 2017-02-18
Expand All @@ -23,7 +23,7 @@ All notable changes to this project will be documented in this file.

## [0.7.5] - 2017-02-17

### fixed
### Fixed
- fix query caching for lumen.

## [0.7.4] - 2017-02-17
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright 2016 <Basem Khirat>
Copyright 2017 <Basem Khirat>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 18 additions & 8 deletions src/ElasticsearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Basemkhirat\Elasticsearch;

use Elasticsearch\ClientBuilder as ElasticBuilder;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\ServiceProvider;
use Laravel\Scout\EngineManager;

Expand Down Expand Up @@ -39,18 +40,27 @@ public function boot()

// Resolve Laravel Scout engine.

if(class_exists("Laravel\\Scout\\EngineManager")) {
if (class_exists("Laravel\\Scout\\EngineManager")) {

$this->app->make(EngineManager::class)->extend('es', function () {
try {

$config = config('es.connections.' . config('scout.es.connection'));
$this->app->make(EngineManager::class)->extend('es', function () {

return new ScoutEngine(
ElasticBuilder::create()->setHosts($config["servers"])->build(),
$config["index"]
);
$config = config('es.connections.' . config('scout.es.connection'));

});
return new ScoutEngine(
ElasticBuilder::create()->setHosts($config["servers"])->build(),
$config["index"]
);

});

} catch (BindingResolutionException $e) {

// Class is not resolved.
// Laravel Scout service provider was not loaded yet.

}

}

Expand Down

0 comments on commit da38796

Please sign in to comment.