@@ -29,11 +29,11 @@ class UserAvatarGenerator
|
||||
protected function generate(User $user): SVG
|
||||
{
|
||||
return $this->generator->rounded()
|
||||
->background($this->getColor($user->name))
|
||||
->background($this->getColor($user->fullName))
|
||||
->color("#F4F8FD")
|
||||
->smooth()
|
||||
->fontSize(0.33)
|
||||
->generateSvg($user->name);
|
||||
->generateSvg($user->fullName);
|
||||
}
|
||||
|
||||
protected function getColor(string $name): string
|
||||
|
@@ -20,7 +20,8 @@ class UserController extends Controller
|
||||
$users = User::query()
|
||||
->withTrashed()
|
||||
->search($request->query("search"))
|
||||
->latest()
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->paginate()
|
||||
->withQueryString();
|
||||
|
||||
|
@@ -14,8 +14,14 @@ class VacationLimitController extends Controller
|
||||
{
|
||||
public function edit(): Response
|
||||
{
|
||||
$limits = VacationLimit::query()
|
||||
->with("user")
|
||||
->orderByUserField("last_name")
|
||||
->orderByUserField("first_name")
|
||||
->get();
|
||||
|
||||
return inertia("VacationLimits", [
|
||||
"limits" => VacationLimitResource::collection(VacationLimit::query()->with("user")->get()),
|
||||
"limits" => VacationLimitResource::collection($limits),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,8 @@ class UserRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
"name" => ["required", "min:3", "max: 150"],
|
||||
"firstName" => ["required", "min:3", "max:80"],
|
||||
"lastName" => ["required", "min:3", "max:80"],
|
||||
"email" => ["required", "email", Rule::unique("users", "email")->ignore($this->user)],
|
||||
"employmentForm" => ["required", new Enum(EmploymentForm::class)],
|
||||
"employmentDate" => ["required", "date"],
|
||||
@@ -24,7 +25,8 @@ class UserRequest extends FormRequest
|
||||
public function data(): array
|
||||
{
|
||||
return [
|
||||
"name" => $this->get("name"),
|
||||
"first_name" => $this->get("firstName"),
|
||||
"last_name" => $this->get("lastName"),
|
||||
"email" => $this->get("email"),
|
||||
"employment_form" => $this->get("employmentForm"),
|
||||
"employment_date" => $this->get("employmentDate"),
|
||||
|
@@ -14,7 +14,8 @@ class UserFormDataResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->name,
|
||||
"firstName" => $this->first_name,
|
||||
"lastName" => $this->last_name,
|
||||
"email" => $this->email,
|
||||
"employmentForm" => $this->employment_form,
|
||||
"employmentDate" => $this->employment_date,
|
||||
|
@@ -14,7 +14,7 @@ class UserResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->name,
|
||||
"name" => $this->fullName,
|
||||
"email" => $this->email,
|
||||
"role" => "Human Resources Manager",
|
||||
"avatar" => asset($this->avatar),
|
||||
|
@@ -16,7 +16,8 @@ use Toby\Enums\EmploymentForm;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $email
|
||||
* @property string $avatar
|
||||
* @property EmploymentForm $employment_form
|
||||
@@ -29,13 +30,7 @@ class User extends Authenticatable
|
||||
use Notifiable;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
"name",
|
||||
"email",
|
||||
"avatar",
|
||||
"employment_form",
|
||||
"employment_date",
|
||||
];
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
"employment_form" => EmploymentForm::class,
|
||||
@@ -58,7 +53,8 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
return $query
|
||||
->where("name", "LIKE", "%{$text}%")
|
||||
->where("first_name", "LIKE", "%{$text}%")
|
||||
->orWhere("last_name", "LIKE", "%{$text}%")
|
||||
->orWhere("email", "LIKE", "%{$text}%");
|
||||
}
|
||||
|
||||
@@ -68,4 +64,9 @@ class User extends Authenticatable
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getFullNameAttribute(): string
|
||||
{
|
||||
return "{$this->first_name} {$this->last_name}";
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -34,4 +35,11 @@ class VacationLimit extends Model
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
|
||||
public function scopeOrderByUserField(Builder $query, string $field): Builder
|
||||
{
|
||||
$userQuery = User::query()->select($field)->whereColumn("vacation_limits.user_id", "users.id");
|
||||
|
||||
return $query->orderBy($userQuery);
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ class UserObserver
|
||||
|
||||
public function updating(User $user): void
|
||||
{
|
||||
if ($user->isDirty("name")) {
|
||||
if ($user->isDirty(["first_name", "last_name"])) {
|
||||
Storage::delete($user->avatar);
|
||||
$user->avatar = $this->generator->generateFor($user);
|
||||
}
|
||||
|
Reference in New Issue
Block a user