exdeliver/elastic

:package_description

dev-main 2023-12-16 19:40 UTC

This package is auto-updated.

Last update: 2024-04-16 20:32:39 UTC


README

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 author@email.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

elastic