change vacation request name
This commit is contained in:
@@ -19,6 +19,7 @@ use Toby\Domain\States\VacationRequest\VacationRequestState;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property VacationType $type
|
||||
* @property VacationRequestState $state
|
||||
* @property Carbon $from
|
||||
@@ -90,6 +91,11 @@ class VacationRequest extends Model
|
||||
->where("to", ">=", $vacationRequest->from);
|
||||
}
|
||||
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return "{$this->id}/{$this->yearPeriod->year}";
|
||||
}
|
||||
|
||||
public function hasFlowSkipped(): bool
|
||||
{
|
||||
return $this->flow_skipped;
|
||||
|
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Observers;
|
||||
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
|
||||
class VacationRequestObserver
|
||||
{
|
||||
public function __construct(
|
||||
protected Auth $auth,
|
||||
protected Dispatcher $dispatcher,
|
||||
) {}
|
||||
|
||||
public function creating(VacationRequest $vacationRequest): void
|
||||
{
|
||||
$year = $vacationRequest->from->year;
|
||||
|
||||
$vacationRequestNumber = $vacationRequest->user->vacationRequests()
|
||||
->whereYear("from", $year)
|
||||
->count() + 1;
|
||||
|
||||
$vacationRequest->name = "{$vacationRequestNumber}/${year}";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user