HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers93/fitale.nl/workbench/komma/kms/src/Komma/Kms/Core/Attributes/KmsDate.php
<?php
/**
 * Short description for the file.
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace Komma\Kms\Core\Attributes;

use Carbon\Carbon;
use View;

class KmsDate extends KmsAttribute{

    public $label;
    public $placeholder;
    public $canNotChange;

    function __construct($key, $value, array $options = [], array $errors = [], $languageId = null, $section = null)
    {
        parent::__construct($key, $value, $options, $errors, $languageId, $section);
        $this->label = $this->getOption('label', $key);
        $this->placeholder = $this->getOption('placeholder', $key);
        $this->canNotChange = $this->getOption('canNotChange', false);
    }

    public function getValue()
    {
        if(!$this->value) return null;
        return Carbon::parse($this->value);
    }

    public function dateForUiWidget()
    {
        if(! $this->value) return '';

        $date = Carbon::parse($this->value);
        if(! $date){
            return '';
        }
        return $date->format('d-m-Y');
    }

    public function canNotChange()
    {
        return !$this->section->isCreatingEntity() && $this->canNotChange;
    }

    public function render()
    {
        return View::make('kms::attributes.date', [
            'attribute' => $this
        ]);
    }

}