Ошибка заполнения: объект класса DateTime не может быть преобразован в строку

Я заполняю свою базу данных с помощью laravel, но получаю эту ошибку. Чтобы удалить его, мне нужно прокомментировать мутаторную часть модели.

public function setBirthdayAttribute($value)
    {   
        $this->attributes['birthday'] = Carbon::createFromFormat('d-m-Y',$value)->format('Y-m-d');
    }

    public function setFirstHireAttribute($value)
    {
        $this->attributes['first_hire'] = Carbon::createFromFormat('d-m-Y',$value)->format('Y-m-d');
    }

Как я могу это исправить? я схожу с ума

Спасибо

Валерио


person netnull    schedule 07.02.2021    source источник
comment
тип дня рождения или first_hire - это строка в migration/db   -  person Beller    schedule 07.02.2021
comment
Нет, это нет. Это дата: $table->date('first_hire');   -  person netnull    schedule 07.02.2021


Ответы (1)


Попробуй это.

public function setBirthdayAttribute($value)
    {   
        $this->attributes['birthday'] = date('Y-m-d',strtotime($value));
    }

    public function setFirstHireAttribute($value)
    {
        $this->attributes['first_hire'] = date('Y-m-d',strtotime($value));
    }
person Rajen Trivedi    schedule 07.02.2021
comment
Я получаю эту ошибку: strtotime() ожидает, что параметр 1 будет строкой, объект задан - person netnull; 07.02.2021
comment
почтовый индекс вашего блейд-файла. - person Rajen Trivedi; 08.02.2021
comment
Что содержит $value? дд ($ значение); - person Beller; 08.02.2021
comment
Это не Blade, это проект Vue.js, основанный на бэкенде Laravel. - person netnull; 08.02.2021
comment
лезвие означает ваш код просмотра... откуда вы отправляете дату. - person Rajen Trivedi; 08.02.2021