Elasticsearch for Laravel Resources
Via Composer
$ composer require exdeliver/elastic
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
Please see the changelog for more information on what has changed recently.
$ composer test
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
MIT. Please see the license file for more information.