CodeIgniter Forums
make:model with default database values - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: make:model with default database values (/showthread.php?tid=85250)



make:model with default database values - [email protected] - 12-09-2022

I think it's great if the default
Code:
php spark make:model
if provided table name then can have optional parameter (true/false) to supplied column names on created model class attributes and also it's default validation rules read from columns metadata.
If standard codeigniter can't include that feature, is there a way to somehow parse the created model file to add those default values?
Thanks.


RE: make:model with default database values - InsiteFX - 12-10-2022

Please Read:

CodeIgniter 4 User Guide - Database Migrations

CodeIgniter 4 User Guide - Spark Commands


RE: make:model with default database values - [email protected] - 12-11-2022

(12-10-2022, 12:25 AM)InsiteFX Wrote: Please Read:

CodeIgniter 4 User Guide - Database Migrations

CodeIgniter 4 User Guide - Spark Commands

Thanks @InsiteFX for pointing out how to make new commands. I'm still new to programming and CI4, i'll definitely look after it for better understanding on CI4. But, so i thought why not provide default values on generated Model file when execute this built in command
Code:
php spark make:model ProductModel --table products
Like primary key, useAutoIncrement, insertID, allowedFields, useTimestamps, dateFormat, and maybe some default validationRules like required, permit_empty, max_length.

PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
User extends Model
{
    protected $DBGroup          'default';
    protected $table            'tuser';
    protected $primaryKey      'id';
    protected $useAutoIncrement true;
    protected $insertID        0;
    protected $returnType      'array';
    protected $useSoftDeletes  false;
    protected $protectFields    true;
    protected $allowedFields    = [];

    // Dates
    protected $useTimestamps false;
    protected $dateFormat    'datetime';
    protected $createdField  'created_at';
    protected $updatedField  'updated_at';
    protected $deletedField  'deleted_at';

    // Validation
    protected $validationRules      = [];
    protected $validationMessages  = [];
    protected $skipValidation      false;
    protected $cleanValidationRules true