#27 - separate fields for name and surname (#29)

* #27 - separate fields for name and surname

* #27 -cr fix
This commit is contained in:
Adrian Hopek
2022-01-24 12:40:56 +01:00
committed by GitHub
parent e147d24365
commit 6854c7a9f8
17 changed files with 127 additions and 48 deletions

View File

@@ -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}";
}
}

View File

@@ -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);
}
}