From 6110e4ac700aff9ec2263cfbfeb4e9d1426fe296 Mon Sep 17 00:00:00 2001 From: MarceauKa Date: Tue, 3 Sep 2019 16:56:35 +0200 Subject: [PATCH] :wrench: Chests can now be searched from their non-sensitive content --- app/Chest.php | 17 +++++++++++++++++ changelog.md | 1 + 2 files changed, 18 insertions(+) diff --git a/app/Chest.php b/app/Chest.php index 28749a7..eb55e30 100644 --- a/app/Chest.php +++ b/app/Chest.php @@ -3,6 +3,7 @@ namespace App; use App\Concerns\Models\Postable; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class Chest extends Model @@ -18,15 +19,31 @@ class Chest extends Model 'content' => 'json', ]; + public function getHashIdAttribute(): string + { + return app('hashid')->encode($this->id); + } + public function getPermalinkAttribute(): string { return route('chest.view', $this->hash_id); } + public function scopeHashIdIs(Builder $query, string $hash): Builder + { + return $query->where('id', app('hashid')->decode($hash)); + } + public function toSearchableArray() { return [ 'title' => $this->title, + 'content' => collect($this->content) + ->reject(function ($item) { + return false === in_array($item['type'], ['url', 'text']); + }) + ->pluck('value') + ->implode("\n"), ]; } } diff --git a/changelog.md b/changelog.md index ad2a02b..3449762 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ - Laravel 6.0 - Simplified Hashid +- Chests can now be searched from their non-sensitive content ## Deleted