mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-25 02:10:39 +00:00
spotlight ability to search users with 'u ' keyword
This commit is contained in:
@@ -134,7 +134,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
public function settings(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserSettings::class);
|
||||
return $this->hasOne(UserSetting::class);
|
||||
}
|
||||
|
||||
public function limitations(): HasOne
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
<?php
|
||||
namespace App\Users\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use TeamTNT\TNTSearch\Indexer\TNTIndexer;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class UserSettings extends Model
|
||||
class UserSetting extends Model
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $guarded = [
|
||||
'id',
|
||||
];
|
||||
protected $guarded = [];
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $table = 'user_settings';
|
||||
|
||||
/**
|
||||
* Format avatar to full url
|
||||
@@ -44,12 +54,40 @@ class UserSettings extends Model
|
||||
return null;
|
||||
}
|
||||
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
$name = mb_convert_encoding(
|
||||
mb_strtolower($this->name, 'UTF-8'),
|
||||
'UTF-8'
|
||||
);
|
||||
|
||||
$nameNgrams = (new TNTIndexer)
|
||||
->buildTrigrams(implode(', ', [$name]));
|
||||
|
||||
$emailNgrams = (new TNTIndexer)
|
||||
->buildTrigrams(implode(', ', [$this->user->email]));
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $name,
|
||||
'nameNgrams' => $nameNgrams,
|
||||
'email' => $this->user->email,
|
||||
'emailNgrams' => $emailNgrams,
|
||||
];
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($user) {
|
||||
$user->color = ['#9ad2bf', '#9ad2cd', '#d29a9a', '#d2ce9a', '#9aadd2', '#c59ad2'][rand(0, 4)];
|
||||
$user->id = Str::uuid();
|
||||
$user->color = ['#9ad2bf', '#9ad2cd', '#d29a9a', '#d2ce9a', '#9aadd2', '#c59ad2'][rand(0, 5)];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace App\Users\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserMinimalResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
'type' => 'users',
|
||||
'attributes' => [
|
||||
'avatar' => $this->settings->avatar,
|
||||
'name' => $this->settings->name,
|
||||
'color' => $this->settings->color,
|
||||
'email' => $this->email,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace App\Users\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class UsersMinimalCollection extends ResourceCollection
|
||||
{
|
||||
public $collects = UserMinimalResource::class;
|
||||
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user