Welcome Guest, Not a member yet? Register   Sign In
Add new option for make:model for specific table

Usually, after building the model, I have to add the names of the fields to $allowedFields.This is time-consuming for me.

I don't know exactly whether other developers have experienced this issue or not.

I suggest to add a new option to command php spark make:modelfor this issue.

Option -for takes the name of the table and adds the fields to $allowedFields
to generate the model.

I think this option helps a lot in saving the developer's time.

Data of Table "sms_sender":

| id | message_text | type | from | to | send_datetime | status | created_at | updated_at | deleted_at |

php spark make:model -for sms_sender

PHP Code:
    protected $DBGroup          'default';
    protected $table            'sms_sender';
    protected $primaryKey      'id';
    protected $useAutoIncrement true;
    protected $returnType      'array';
    protected $useSoftDeletes  true;
    protected $protectFields    true;
    protected $allowedFields    = [

I like this idea.

No problem. Good idea!

I agree. I myself had tables of the type date_1, date_N... When creating, it is important to take into account the primary key

Yes, good idea but somefields will not need to be in allowFields.

So we will need to look into that.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

i agree too @datamweb
Codeigniter First, Codeigniter Then You!!


(07-27-2023, 10:35 PM)InsiteFX Wrote: Yes, good idea but somefields will not need to be in allowFields.

So we will need to look into that.
For example? Default dates can be added (created_at, etc). ID as the `id` field to ignore. There is a problem if the ID is of a different type (`product_id`). Then you need to request it from the console. After creating the model, remind the developer to check these fields

ID and timestamps are not needed in $allowedFields.

I also agree that it's a good idea.

The option --table was implemented.

$ php spark make:model --help

CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-11-01 02:59:10 UTC+00:00

  make:model <name> [options]

  Generates a new model file.

  name  The model class name.

  --table      Supply a table name. Default: "the lowercased plural of the class name".
  --dbgroup    Database group to use. Default: "default".
  --return    Return type, Options: [array, object, entity]. Default: "array".
  --namespace  Set root namespace. Default: "APP_NAMESPACE".
  --suffix    Append the component title to the class name (e.g. User => UserModel).
  --force      Force overwrite existing file.

Theme © iAndrew 2016 - Forum software by © MyBB