Skip to content

exdeliver/elastic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elastic

Elasticsearch for Laravel Resources

Installation

Via Composer

$ composer require exdeliver/elastic

Usage

Create a resource and define the data to be imported by resources.

php artisan make:resource PhoneNumberResource


<?php

namespace App\Http\Resources;

use App\Models\PhoneNumber;
use Exdeliver\Elastic\Resources\ElasticSearchResource;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class PhoneNumberResource extends ElasticSearchResource
{
    public const ELASTIC_INDEX = 'phone_numbers';

    public static function model(): Model
    {
        return new PhoneNumber();
    }

    public function toElastic(Request $request): array
    {
        /**
         * Data from the model that should be imported
         */
        return [
            'index' => self::ELASTIC_INDEX,
            'body' => [
                'uuid' => $this->uuid,
                'number' => $this->phonenumber,
                'contact' => ContactResource::make($this->contact), // supports make() and collection()
            ],
        ];
    }

    public static function elastic(): array
    {
        return [
            'index' => self::ELASTIC_INDEX,
        ];
    }
}

Your controllewr

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

elastic

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages