mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-29 11:15:58 +00:00
Searching backend
This commit is contained in:
@@ -7,10 +7,12 @@ use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Scout\Searchable;
|
||||
use TeamTNT\TNTSearch\Indexer\TNTIndexer;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, Searchable;
|
||||
|
||||
protected $casts = [
|
||||
'items' => 'array',
|
||||
@@ -34,12 +36,32 @@ class Invoice extends Model
|
||||
return $this->hasOne(Client::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Index file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toSearchableArray()
|
||||
{
|
||||
$array = $this->toArray();
|
||||
|
||||
$client_name = Str::slug($array['client']['name'], ' ');
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'clientName' => $array['client']['name'],
|
||||
'clientNameNgrams' => utf8_encode((new TNTIndexer)->buildTrigrams(implode(', ', [$client_name]))),
|
||||
'invoiceNumber' => $array['invoice_number'],
|
||||
'invoiceNumberNgrams' => utf8_encode((new TNTIndexer)->buildTrigrams(implode(', ', [$array['invoice_number']]))),
|
||||
];
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($invoice) {
|
||||
$invoice->id = Str::uuid();
|
||||
$invoice->id = (string)Str::uuid();
|
||||
|
||||
$invoice->delivery_at = $invoice->created_at;
|
||||
$invoice->due_at = Carbon::parse($invoice->created_at)->addWeeks(2);
|
||||
|
||||
Reference in New Issue
Block a user