弹性搜索配置在laravel v5.3中不起作用

I have setup new laravel v5.3 project and install elastic search driver to implement elastic search via composer. But when I reload my page then I always receive This page isn’t working even the elastic search is running on my system below is my complete code that I code.

composer.json

"require": {
        "php": ">=5.6.4",
        "elasticsearch/elasticsearch": "^6.0",
        "laravel/framework": "5.3.*"
    },

web.php

Route::get('/',array('uses' => 'ElasticSearch@addPeopleList'));

Controller

<?php
namespace App\Http\Controllers;    
class ElasticSearch extends Controller
    {

        // elastic
        protected $elastic;
        //elastic cliend
        protected $client;

        public function __construct(Client $client)
        {
            $this->client = ClientBuilder::create()->build();
            $config = [
                'host' =>'localhost',
                'port' =>9200,
                'index' =>'people',
            ];
            $this->elastic = new ElasticClient($config);
        }

        public function addPeopleList(){
            echo "<pre>";
            print_r($this->$elastic);
            exit;
        }
    }

But when I refresh the page then This page isn’t working i received this message and page not loaded one thing that I want to let you know that I made no changes in app.php file of configuration. Please eduacate to solve this issue.

if You want to instantiate an elastic client with some configuration, You should use method ClientBuilder::fromConfig(array $config). In your case it should be

<?php
$client = ClientBuilder::fromConfig([
    'hosts' => [ 'localhost:9200' ]
]);

As You can notice above hosts must be provided as array.

Also I'm not sure that Elasticsearch client that You use have ElasticClient class.

Also if You provided actual code from your controller than it contains an error. You should call class properties like that: print_r($this->client) (without $ near the property name).

Finaly your controller should looks like this:

<?php
namespace App\Http\Controllers;

use Elasticsearch\ClientBuilder;

class ElasticSearch extends Controller
{
    /**
     * @var \Elasticsearch\Client
     */
    protected $client;

    public function __construct()
    {
        $this->client = ClientBuilder::fromConfig([
            'hosts' => [
                'localhost:9200',
            ],
        ]);
    }
    public function addPeopleList(){
        echo "<pre>";
        print_r($this->client);
        exit;
    }
}

And to add a document to the index You need to call this command according to the official documentation

$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
    'body' => ['testField' => 'abc']
];

$response = $client->index($params);
print_r($response);

Official documentation can be found here https://github.com/elastic/elasticsearch-php

P.S. Sorry for my English. It is far from perfect.