* change layout * change layout * #22 - wip * wip * wip * #22 - wip * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - added some tests * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - cr fixes * #22 - cr fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
@@ -28,6 +28,7 @@ use Toby\Domain\Enums\Role;
|
||||
* @property Carbon $employment_date
|
||||
* @property Collection $vacationLimits
|
||||
* @property Collection $vacationRequests
|
||||
* @property Collection $vacations
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -57,6 +58,11 @@ class User extends Authenticatable
|
||||
return $this->hasMany(VacationRequest::class);
|
||||
}
|
||||
|
||||
public function vacations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vacation::class);
|
||||
}
|
||||
|
||||
public function scopeSearch(Builder $query, ?string $text): Builder
|
||||
{
|
||||
if ($text === null) {
|
||||
|
43
app/Eloquent/Models/Vacation.php
Normal file
43
app/Eloquent/Models/Vacation.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
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 Carbon $date
|
||||
* @property User $user
|
||||
* @property VacationRequest $vacationRequest
|
||||
* @property YearPeriod $yearPeriod
|
||||
*/
|
||||
class Vacation extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
"date" => "date",
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function vacationRequest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(VacationRequest::class);
|
||||
}
|
||||
|
||||
public function yearPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
}
|
@@ -21,11 +21,11 @@ use Toby\Domain\Enums\VacationType;
|
||||
* @property VacationRequestState $state
|
||||
* @property Carbon $from
|
||||
* @property Carbon $to
|
||||
* @property int $estimated_days
|
||||
* @property string $comment
|
||||
* @property User $user
|
||||
* @property YearPeriod $yearPeriod
|
||||
* @property Collection $activities
|
||||
* @property Collection $vacations
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*/
|
||||
@@ -57,6 +57,11 @@ class VacationRequest extends Model
|
||||
return $this->hasMany(VacationRequestActivity::class);
|
||||
}
|
||||
|
||||
public function vacations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vacation::class);
|
||||
}
|
||||
|
||||
public function changeStateTo(VacationRequestState $state): void
|
||||
{
|
||||
$this->state = $state;
|
||||
@@ -69,6 +74,11 @@ class VacationRequest extends Model
|
||||
return $query->whereIn("state", $states);
|
||||
}
|
||||
|
||||
public function scopeNoStates(Builder $query, array $states): Builder
|
||||
{
|
||||
return $query->whereNotIn("state", $states);
|
||||
}
|
||||
|
||||
public function scopeOverlapsWith(Builder $query, self $vacationRequest): Builder
|
||||
{
|
||||
return $query->where("from", "<=", $vacationRequest->to)
|
||||
|
Reference in New Issue
Block a user