E
E
Eugene2018-07-17 15:22:11
Laravel
Eugene, 2018-07-17 15:22:11

Why is the Unexpected data found error displayed?

Task: add the ability to specify the time for the published_at attribute.

<div class="form-group">
    {!! Form::label('published_at',"Дата публикации :") !!}
    {!! Form::input('datetime-local', 'published_at', date('Y-m-d H:i'), ['class' => 'form-control', 'min' => date('Y-m-d') ]) !!}
</div>

Model
public function setPublishedAtAttribute($date) {
        //dd($date);
        $this->attributes['published_at'] = Carbon::createFromFormat('Y-m-d H:i', $date)->format('Y-m-d H:i');
    }

dd variable $date returns:
"2018-07-18T15:15"

Accepted the Ym-dTH:i format, but then an error occurred:
InvalidArgumentException
The timezone could not be found in the database Data missing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Hog, 2018-07-17
@Eugene70

Escape the time zone abbreviation "T"
Carbon::createFromFormat('Y-m-d\TH:i', $date)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question