0
votes

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

2
What error you are getting when you are trying with this updated_at = Carbon::now()->timestamp; ?Prashant Deshmukh.....
pease go database.. change type updated_at to timestamp and set default null or current timestamp ...نور
Why updated_at set as integer? it should be timestamp, go to pogres admin and check column format. In your migration you have $table->timestamps(); or you've modified updated_at ?sta
default type is not datetime , default format is timestamp both are different. Would you please share the migration file?sta
please try it.. date('Y-m-d h:i:s ', strtotime($date)); or date('Y-m-d h:i:s');نور

2 Answers

0
votes

If the columns were timestamp with/without time zone as they should, you could simply use current_timestamp or localtimestamp.

This way, you will have to use the more complicated

EXTRACT(epoch FROM current_timestamp)`
-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 {
  ...
}