Iam using Laravel 8
i made all steps to change table->timestamp()
to unix-timstamp
but its return in ‘2022-10-10T21:09:28.000000Z’
in Model.php
class Post extends Model
{
HasFactory;
protected $dateFormat = 'U';
}
in create_post_table.php
$table->unsignedInteger('created_at');
$table->unsignedInteger('updated_at');
result in data base:
return response()->json result:
i need to return in ‘1665434137’ format ??
2
Answers
found answer in this question
in modal.php add
Hi please follow these steps :
in your migration file ,change the
to
it will automatically create two columns in your table
Also please drop $casts and $dataFormat in your model.php file ,you don’t need them anymore .
Finaly to achieve your result it is enough to do this :
Notice the Model in above code should be replaced with the model object you have , for example :
or any other method of post object .