That we have the advantage of defining a field that is automatically filled with the current date at the time the record is created and more interesting, that when we edit that record, the current date is defined, it is something extremely simple in frameworks like Laravel and that in CodeIgniter 4, we can also use in a simple way. We need to define about 3 attributes in our model:
- $useTimestamps - Boolean that indicates if you are going to enable the timestamp for creation and update.
- $createdField - Define the name of the column of the creation field.
- $updatedField - Define the name of the update field column.
For example, in the following model, we define the corresponding properties along with the 3 noted above:
<?php
namespace App\Models;
use CodeIgniter\Model;
class ProductsControlModel extends Model
{
protected $table = 'products_control';
protected $primaryKey = 'id';
protected $allowedFields = ['product_id', 'type','count', 'created_at', 'updated_at'];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter