CastsTo.php 601 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

namespace Source\Sanitize;

use Carbon\Carbon;

trait CastsTo
{
    /**
     * @param $date
     * @param string $format
     * @return \Carbon\Carbon|null
     */
    protected function castToDate($date, $format = 'Y-m-d H:i:s'): ?Carbon
    {
        if (empty($date)) {
            return null;
        }

        return Carbon::createFromFormat($format, $date);
    }
Jacob Priddy's avatar
Jacob Priddy committed
22
23
24
25
26
27
28
29
30
31
32
33
34

    /**
     * @param string|null $int
     * @return int|null
     */
    protected function castToInt(?string $int): ?int
    {
        if (!$int) {
            return null;
        }

        return (int)$int;
    }
35
}