"Timestamp" column type not handled by Laravel package

Feature(s) impacted

Handle “timestamp” type columns in Laravel package.

Observed behavior

Failed on error : Undefined array key “timestamp” during setup.

Expected behavior

“Timestamp” column type handle during setup.

Failure Logs

ErrorException 

 Undefined array key "timestamp"

 at vendor/forestadmin/laravel-forestadmin/src/Schema/Concerns/DataTypes.php:53
    49▕      * @return string
    50▕      */
    51▕     public function getType(string $dbType): string
    52▕     {
 ➜  53▕         return $this->dbTypes[$dbType];
    54▕     }
    55▕ }
    56▕ 

     +12 vendor frames 
 13  artisan:37
     Illuminate\Foundation\Console\Kernel::handle()

Context

I’m using Laravel ForestAdmin package with a MySQL database. Several fields are “Timestamp”, like auto-generated laravel fields “created_at” and “updated_at”.

I’ve previously created a github issue : Undefined array key "timestamp" · Issue #54 · ForestAdmin/laravel-forestadmin · GitHub

I’ve been in a call with Louis and Sami, asking me to create this issue in the community instead of Github.

Hi @storm23, and welcome to our community :wave:

I’m not able to reproduce the problem on my end.

What is your MYSQL version?

Mysql 8.0.22

When I look at the code (laravel-forestadmin/DataTypes.php at main · ForestAdmin/laravel-forestadmin · GitHub) I don’t see “timestamp” type.

Doctrine is supposed to convert the SQL type timestamp to datetime

See: dbal/AbstractMySQLPlatform.php at 3.3.x · doctrine/dbal · GitHub

Could you share one of your model with its migration. That could help to reproduce your issue. :pray:

Hello,

Here is the table :

CREATE TABLE `analytics` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `created_at` timestamp NULL DEFAULT NULL,
  `price` bigint DEFAULT NULL,
  `total_price` bigint DEFAULT NULL,
  `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4893566 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Here is the Laravel Model

class Analytics extends Model
{
    use HasFactory;

    protected $table = 'analytics';
    public $timestamps = false;
}

Regards

Hello,

I can’t reproduce your issue with your model and migration.

Did you add a new DBAL Timestamps type in your database config like in this Laravel documentation example ? (Database: Migrations - Laravel - The PHP Framework For Web Artisans)

Yes I have already this config.

In your test, what’s the value “$dbType” passed to DataTypes\GetType for the “created_at” field and the returned value ?

I’m able to reproduce your issue by adding this type in my config.

Unfortunately this config is not currently supported.

I’ll opening a ticket on our end.

Hi @storm23,

This feature is now available in the latest version (v1.1.1) of laravel-forestadmin.