Welcome Guest, Not a member yet? Register   Sign In
make:model with default database values
#1

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.
Reply
#2

Please Read:

CodeIgniter 4 User Guide - Database Migrations

CodeIgniter 4 User Guide - Spark Commands
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB