我一直在获取无效的日期时间格式:1292



型号

class ClickMeeting extends Model
{
protected $table = 'clickmeeting';
public $timestamps = false;
protected $dateFormat = 'U';
protected $guarded = ['id'];
static $videoDemoSource = ['upload', 'youtube', 'vimeo', 'external_link'];
public function ClickMeeting()
{
///
}
}

控制器

public function dashboard()
{
$client = new Client();
$uri = 'https://api.clickmeeting.com/v1/conferences/active';
$header = ['headers' => ['X-Api-Key' => 'xxxxxxxxxxxxxxxxxxxxxxxx']];
$res = $client->get($uri, $header);
$conferences = json_decode($res->getBody()->getContents(), true);
// dd($conferences);
collect($conferences)
->each(function ($conference, $key) {
ClickMeeting::firstOrCreate([
'parent_id' => $conference['parent_id'],
'room_type' => $conference['room_type'],
'room_url' => $conference['room_url'],

],
[
'starts_at' => $conference['starts_at'],
'ends_at' => $conference['ends_at'],
'room_pin' => $conference['room_pin'],
'title' => $conference['name'],
'name_url' => $conference['name_url'],
'access_type' => $conference['access_type'],
'lobby_enabled' => $conference['lobby_enabled'],
'lobby_description' => $conference['lobby_description'],
'registration_enabled' => $conference['registration_enabled'],
'status' => $conference['status'],
'timezone' => $conference['timezone'],
'timezone_offset' => $conference['timezone_offset'],
'paid_enabled' => $conference['paid_enabled'],
'automated_enabled' => $conference['automated_enabled'],
'type' => $conference['type'],
'permanent_room' => $conference['permanent_room'],
'embed_room_url' => $conference['embed_room_url']
]);
});
$conferences = ClickMeeting::get();
return view('admin.clickmeeting.dashboard',compact('conferences'));

SQLSTATE〔22007〕:无效的日期时间格式:1292不正确的日期时间第1行"starts_at"列的值:"2022-06-22T16:10:00+00:00"(SQL:插入到clickmeeting(parent_idroom_typeroom_urlstarts_atends_atroom_pintitlename_urlaccess_typelobby_enabledlobby_descriptionregistration_enabledstatustimezonetimezone_offsetpaid_enabledautomated_enabledtypepermanent_roomembed_room_url)值(,https://abc.clickmeeting.com/urinary-tract-infection-in-children,2022-06-22T16:10:00+00:00,2022-06-22T17:10:00+00:00477736894,儿童尿路感染,非洲/阿克拉活动期1、1、1岁儿童尿路感染,0,0,0,https://abc.clickwebinar.com/embed_conference.html?r=123456))

我一直得到无效的日期时间格式:1292不正确的日期时间值。我们非常感谢您的帮助。谢谢

我认为出现这些情况是因为上面语句中的DATETIME值使用了MySQL不支持的格式,您可以使用STR_TO_DATE()函数将starts_at变量传递到数据库中。

类似的代码

'starts_at' => STR_TO_DATE($conference['starts_at'], "%m-%d-%Y %H:%i:%s"),

请查看此链接,您可以找到更多关于STR_TO_DATE()函数的信息

尝试使用CarbonCarbon分配日期:

collect($conferences)
->each(function ($conference, $key) {
ClickMeeting::firstOrCreate([
....
],
[
'starts_at' => Carbon::parse($conference['starts_at']),
'ends_at' => Carbon::parse($conference['ends_at']),
....
]);
});

或者,您可以使用$casts属性告诉laravel哪些字段是日期:

class ClickMeeting extends Model
{
....
protected $guarded = ['id'];
protected $casts = [
'starts_at' => 'datetime',
'ends_at' => 'datetime'
];
....
}

相关内容

最新更新