I want add days to created at in database but get this error in laravel,
Unexpected data found. Trailing data
format column created_at is datetime
$packages = Package::find($id);
$licenceF = Licence::where('tbl_package_id' , $id)
->select('created_at')
->get();
$date = Carbon::createFromFormat('Y-m-d', $licenceF);
$findPackage = Package::where('id' , $request->input('tbl_package_id'))->pluck('time');
$licenceF = $licenceF->addDays($findPackage);
2
Answers
I write this code for change each license created_at, but date of first row in database update for all column
Use
Carbon::parse()
instead ofCarbon::createFromFormat()
as follows :$licenceF = Carbon::parse($findPackage[0]->created_at)->addDays($findPackage);
You can get the query result as an array as well using :
$licenceF = License::where('tbl_package_id' , $id)->select('created_at')->get()->toArray()
and later using
$licenceF[0]['created_at']
The difference between
parse
andcreateFromFormat
is that the second method tries to "guess" the format of the date string you pass as an argument. This might be handy if you have your own class for date manipulation.I hope I was helpful