* #23 - wip * #23 - wip * #23 - wip * #23 - wip * #23 - fix * #23 - ecs fix * #23 - fix * #23 - fix * #23 - cr fix
This commit is contained in:
@@ -6,10 +6,12 @@ namespace Toby\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Enums\EmploymentForm;
|
||||
|
||||
/**
|
||||
@@ -19,6 +21,7 @@ use Toby\Enums\EmploymentForm;
|
||||
* @property string $avatar
|
||||
* @property EmploymentForm $employment_form
|
||||
* @property Carbon $employment_date
|
||||
* @property Collection $vacationLimits
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -43,6 +46,11 @@ class User extends Authenticatable
|
||||
"remember_token",
|
||||
];
|
||||
|
||||
public function vacationLimits(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationLimit::class);
|
||||
}
|
||||
|
||||
public function scopeSearch(Builder $query, ?string $text): Builder
|
||||
{
|
||||
if ($text === null) {
|
||||
@@ -53,4 +61,11 @@ class User extends Authenticatable
|
||||
->where("name", "LIKE", "%{$text}%")
|
||||
->orWhere("email", "LIKE", "%{$text}%");
|
||||
}
|
||||
|
||||
public function saveAvatar(string $path): void
|
||||
{
|
||||
$this->avatar = $path;
|
||||
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
37
app/Models/VacationLimit.php
Normal file
37
app/Models/VacationLimit.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property User $user
|
||||
* @property YearPeriod $yearPeriod
|
||||
* @property int $days
|
||||
*/
|
||||
class VacationLimit extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function hasVacation(): bool
|
||||
{
|
||||
return $this->days !== null;
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function yearPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
}
|
@@ -7,10 +7,13 @@ namespace Toby\Models;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $year
|
||||
* @property Collection $vacationLimits
|
||||
*/
|
||||
class YearPeriod extends Model
|
||||
{
|
||||
@@ -27,4 +30,9 @@ class YearPeriod extends Model
|
||||
|
||||
return $year;
|
||||
}
|
||||
|
||||
public function vacationLimits(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationLimit::class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user