Skip to content

Commit

Permalink
🔧 Chests can now be searched from their non-sensitive content
Browse files Browse the repository at this point in the history
  • Loading branch information
MarceauKa committed Sep 3, 2019
1 parent 15920cb commit 6110e4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/Chest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
];
}
}
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Laravel 6.0
- Simplified Hashid
- Chests can now be searched from their non-sensitive content

## Deleted

Expand Down

0 comments on commit 6110e4a

Please sign in to comment.