I have a problem with inserting into table where updated_at, created_at, deleted_at have type integer. But as I understood, this columns have default type datetime and when I update note, I have an error like Invalid text representation: 7 ERROR: invalid input syntax for type integer: "2020-09-28 04:21:06". Therefore when I create a new note, I added this updated_at = Carbon::now()->timestamp; But it does not work and I can't change structure of table and type of column
0
votes
2 Answers
0
votes
-1
votes
Check Date mutators documentation and set dateformat in your Model
/**
* The storage format of the model's date columns.
*
* @var string
*/
protected $dateFormat = 'U';
Modify your model's migration:
Replace
$table->timestamps();
with
$table->unsignedInteger('created_at');
$table->unsignedInteger('updated_at');
Secondly, if you don't want to set the $dateFormat for all your models individually, set it in BaseModel and make all your models extend that class:
class BaseModel extends Illuminate\Database\Eloquent\Model {
protected $dateFormat = 'U';
}
class User extends BaseModel {
...
}
updated_at = Carbon::now()->timestamp;? - Prashant Deshmukh.....updated_attotimestampand set defaultnullorcurrent timestamp... - نورupdated_atset as integer? it should betimestamp, go to pogres admin and check column format. In your migration you have$table->timestamps();or you've modifiedupdated_at? - stadatetime, default format istimestampboth are different. Would you please share the migration file? - stadate('Y-m-d h:i:s ', strtotime($date));ordate('Y-m-d h:i:s');- نور