Merge branch 'main' into directory-refactor

# Conflicts:
#	app/Architecture/Providers/AppServiceProvider.php
#	app/Eloquent/Observers/YearPeriodObserver.php
This commit is contained in:
Adrian Hopek
2022-01-26 08:58:57 +01:00
33 changed files with 979 additions and 55 deletions

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Database\Factories\HolidayFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
/**
* @property int $id
* @property string $name
* @property Carbon $date
* @property YearPeriod $yearPeriod
*/
class Holiday extends Model
{
use HasFactory;
protected $guarded = [];
protected $casts = [
"date" => "date",
];
public function yearPeriod(): BelongsTo
{
return $this->belongsTo(YearPeriod::class);
}
protected static function newFactory(): HolidayFactory
{
return HolidayFactory::new();
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -34,7 +35,7 @@ class User extends Authenticatable
protected $casts = [
"employment_form" => EmploymentForm::class,
"employment_date" => "datetime",
"employment_date" => "date",
];
protected $hidden = [
@@ -69,4 +70,9 @@ class User extends Authenticatable
{
return "{$this->first_name} {$this->last_name}";
}
protected static function newFactory(): UserFactory
{
return UserFactory::new();
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Database\Factories\VacationLimitFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -42,4 +43,9 @@ class VacationLimit extends Model
return $query->orderBy($userQuery);
}
protected static function newFactory(): VacationLimitFactory
{
return VacationLimitFactory::new();
}
}

View File

@@ -4,29 +4,34 @@ declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Carbon\Carbon;
use Database\Factories\YearPeriodFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
/**
* @property int $id
* @property int $year
* @property Collection $vacationLimits
* @property Collection $holidays
*/
class YearPeriod extends Model
{
use HasFactory;
protected $fillable = [
"year",
];
protected $guarded = [];
public static function current(): ?static
{
return static::findByYear(Carbon::now()->year);
}
public static function findByYear(int $year): ?static
{
/** @var YearPeriod $year */
$year = static::query()->where("year", Carbon::now()->year)->first();
$year = static::query()->where("year", $year)->first();
return $year;
}
@@ -35,4 +40,14 @@ class YearPeriod extends Model
{
return $this->hasMany(VacationLimit::class);
}
public function holidays(): HasMany
{
return $this->hasMany(Holiday::class);
}
protected static function newFactory(): YearPeriodFactory
{
return YearPeriodFactory::new();
}
}