dongxieli3839 2019-03-14 08:46
浏览 326

当日期格式正确并且数据也存储但仍然出现错误时,laravel中的数据缺失错误

Hi guys i am working with laravel 5.7 while inserting data im getting issue of "Data Missing" but the data is inserting as well but still getting error here im sharing part of my code

Model

public function setApplicationDateAttribute($input)
{
    if($input != '') {
        $this->attributes['application_date'] = Carbon::createFromFormat(config('quickadmin.date_format'), $input)->format('Y-m-d');
    }else{
        $this->attributes['application_date'] = '';
    }
}

this is the funtion which is checking the date format for input data Now this is a file in my config folder named quickadmin i will show you the code of it

return [

/**
 * Datepicker configuration:
 */
'date_format'        => 'Y-m-d',
'date_format_jquery' => 'yy-mm-dd',
'time_format'        => 'H:i:s',
'time_format_jquery' => 'HH:mm:ss',

/**
 * Quickadmin settings
 */
'route'              => 'admin',
'homeRoute'          => 'admin',
'defaultRole'        => 1];

Now here is the code of Controller

$locumApplications = ModelName::create([
               'user_id' => $request->user_id,
               'locum_id' => $request->locum_id,
               'application_date' => $request->application_date
           ]);

it insert the data but give me error and if i remove the line 'application_date' => $request->application_date it still show me the error

here i attached the error image enter image description here

  • 写回答

2条回答 默认 最新

  • dongshuofu0039 2019-03-14 08:52
    关注

    Your config: config('quickadmin.date_format') is Y-m-d

    You are trying to set attributes

    Carbon::createFromFormat(config('quickadmin.date_format'), $input)->format('Y-m-d');
    

    Your $input ($request->application_date) must be on Y-m-d format

    Should be work

    \Carbon\Carbon::createFromFormat('Y-m-d', '2019-03-14')->format('Y-m-d') //OP: 2019-03-14
    

    Your date input and set attributes value look like the same format

    评论

报告相同问题?