From d7d579d66141be681325c06634071f2b2836abb2 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Wed, 18 May 2022 09:20:51 -0600 Subject: [PATCH] adding search stuff to Laravel model --- Packages/User/laravel_model.sublime-snippet | 56 ++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/Packages/User/laravel_model.sublime-snippet b/Packages/User/laravel_model.sublime-snippet index c10a1c3..70007ae 100644 --- a/Packages/User/laravel_model.sublime-snippet +++ b/Packages/User/laravel_model.sublime-snippet @@ -4,9 +4,11 @@ use App\Models\Traits\HasUidTrait; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Prunable; +use Laravel\Scout\Searchable; use HasUidTrait; use Prunable; +use Searchable; /** @var string */ protected \$table = ''; @@ -78,6 +80,58 @@ protected function pruning(): void // } +/** + * Get the value used to index the model. + * + * @since 1.0.0 + * + * @return mixed + */ +public function getScoutKey() +{ + return \$this->id; +} + +/** + * Get the key name used to index the model. + * + * @since 1.0.0 + * + * @return string + */ +public function getScoutKeyName(): string +{ + return 'id'; +} + +/** + * Get the name of the index associated with the model. + * + * @since 1.0.0 + * + * @return string + */ +public function searchableAs(): string +{ + return 'models_index'; +} + +/** + * Get the indexable data array for the model. + * + * @since 1.0.0 + * + * @return array + */ +public function toSearchableArray(): array +{ + \$payload = \$this->toArray(); + + // modify here... + + return \$payload; +} + /* |-------------------------------------------------------------------------- | Accessors @@ -95,7 +149,7 @@ protected function pruning(): void protected function attrName(): Attribute { return Attribute::make( - get: fn ($value, $attributes) => $attributes['foo'], + get: fn (\$value, \$attributes) => \$attributes['foo'], ); }