aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Reservation.php
blob: 733571e7579f625ad2ecd8addbe7d7a5a9a0fded (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

use Carbon\Carbon;

class Reservation extends Model
{
    use HasFactory;

    public function getFromTimeAttribute() {
        return Carbon::parse($this->attributes['fromTime'])->format('d.m.Y. H:i');
    }

    public function setFromTimeAttribute($value) {
        $this->attributes['fromTime'] = Carbon::createFromFormat('d.m.Y. H:i', $value)->toDateTimeString();
    }

    public function getToTimeAttribute() {
        return Carbon::parse($this->attributes['toTime'])->format('d.m.Y. H:i');
    }

    public function setToTimeAttribute($value) {
        $this->attributes['toTime'] = Carbon::createFromFormat('d.m.Y. H:i', $value)->toDateTimeString();
    }

    // I am quite sure this not working is a bug.
    //protected function serializeDate(\DateTimeInterface $date)
    //{
        //return $date->format('d.m.Y. H:i');
    //}

    protected $casts = [
      'fromTime' => 'datetime:d.m.Y. H:i',
      'toTime' => 'datetime:d.m.Y. H:i',
    ];
}