mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 02:50:39 +00:00
Searching backend
This commit is contained in:
@@ -6,10 +6,12 @@ use App\Models\User;
|
||||
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 Client extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, Searchable;
|
||||
|
||||
public $guarded = ['id'];
|
||||
|
||||
@@ -27,12 +29,33 @@ class Client extends Model
|
||||
return $this->hasMany(Invoice::class, 'client_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Index file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toSearchableArray()
|
||||
{
|
||||
$array = $this->toArray();
|
||||
|
||||
$client_name = Str::slug($array['name'], ' ');
|
||||
$client_email = Str::slug($array['email'], ' ');
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'clientName' => $array['name'],
|
||||
'clientNameNgrams' => utf8_encode((new TNTIndexer)->buildTrigrams(implode(', ', [$client_name]))),
|
||||
'clientEmail' => $array['email'],
|
||||
'clientEmailNgrams' => utf8_encode((new TNTIndexer)->buildTrigrams(implode(', ', [$client_email]))),
|
||||
];
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($order) {
|
||||
$order->id = Str::uuid();
|
||||
$order->id = (string) Str::uuid();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user