Reputation: 7086
When I run the system, there is exist error like this :
InvalidArgumentException in Carbon.php line 425: Data missing
in Carbon.php line 425
at Carbon::createFromFormat('Y-m-d H:i:s', '10-12-2016') in Model.php line 2990
at Model->asDateTime('10-12-2016') in Model.php line 2944
at Model->fromDateTime('10-12-2016') in Model.php line 2872
at Model->setAttribute('tglkop', '10-12-2016') in Model.php line 442
And my model is like this :
<?php
namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class P3 extends Model
{
use SoftDeletes;
public $table = 'p3_s';
protected $dateFormat = 'Y-m-d';
protected $dates = ['deleted_at', 'tglkop', 'tglp3'];
public $fillable = [
'id_pagu',
'id_p3',
'kdbulan',
'thang',
'nokop',
'tglkop',
'tglp3'
];
protected $casts = [
'id_pagu' => 'string',
'id_p3' => 'string',
'kdbulan' => 'string',
'thang' => 'string',
'nokop' => 'string'
];
public static $rules = [
'id_pagu' => 'required',
'id_p3' => 'required',
'kdbulan' => 'required',
'thang' => 'required',
'nokop' => 'required',
'tglkop' => 'required',
'tglp3' => 'required',
];
}
My table is like this :
id, int(10)
id_pagu, varchar(18)
id_p3, varchar(18)
kdbulan, varchar(2)
thang, varchar(4)
nokop, varchar(10)
tglkop, date
tglp3, date
created_at, timestamp
updated_at, timestamp
deleted_at, timestamp
I read some tutorial in stackoverflow and laravel docs, but I'm still confused to implement it
Is there any solution to solve my problem?
Upvotes: 0
Views: 4933
Reputation: 1
I had this same issue when deploying a Laravel application in AWS Elastic Beanstalk environment.
The solution was to change the date column from timestamp(1) to DATETIME on the MySQL database.
Hope this helps!
Upvotes: 0
Reputation: 1282
Just remove 'tglkop', 'tglp3'
from your $casts
array, and add this to '$dates'
array. These properties will be automatically converted to Carbon
instances
UPDATE
I guess that your db columns tglkop
and tglp3
have DATE
type instead of DATETIME
.
This error
Carbon::createFromFormat('Y-m-d H:i:s', '10-12-2016') in blah blah blah
says that Carbon
expects date with format Y-m-d H:i:s
but you gives date in format d-m-Y
(10-12-2016
)
Solution 1:
change type of these columns to DATETIME
Solution 2: add that in your model
protected $dateFormat = 'Y-m-d'; // this is expected format for `MySQL` `DATE` type field
UPDATE 2
I think you tries to create row in database. What data are you trying to pass into? I think tglkop
and tglp3
fields in your input have wrong format.
Upvotes: 5