0 votes

I have some ideas on you can make skipper more useful if you are open to hear it.

First I am using CI3 as a framework. It is outdated and the creators have left CI 3 users without a path to upgrade to CI4.

I started using illuminate eloquent in my project to get more modern ORM features. It has been great.

I am able to use skipper to get a jump on the creation of the models, but with a lot of manual modification. Mostly done with rename utilities and also some python scripts.

I think it is good, but it would be much nicer if I had more control over what was generated.

For example, I setup my name space as Models;

This way all the illuminate eloquent models won't interfere with everything else. I also don't really like having abstract models and then normal models. My models aren't so large I can't just use them directly. If we had the ability to change the name space and imports and also using abstract classes or not I think it would make it so I can use skipper without doing any additional modifications. I understand why you would use abstract models when using a generator though, but since my use case is more of a 1 time setup it doesn't make as much sense.

Normally I just create my models as I go now, but still using skipper is a nice thing to have just to stay up to date and look at how everything is progressing. I first used skipper like a year ago.

So if you can, please give more ability to customize a Laravel like environment using Eloquent but maybe not Laravel as a whole.

I want to use laravel and maybe some time down the line the project will be completely converted, but until then it requires much more work on my part.

I know using Eloquent as a stand alone package is pretty popular. I even use schema builder as well for migrations although wrapped in some CI3 controllers specific to CI3 migrations. For example.

<?php

use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;

class Migration_PeoplePhone_authorized_add extends CI_Migration {
  private $table = "person_phones";

  public function __construct() {
      parent::__construct();
  }

  public function up() {
    if(Capsule::schema()->hasTable($this->table)) {
      Capsule::schema()->table($this->table, function (Blueprint $table) {
        $table->boolean('authorized')->after('receive_texts')->default(0)->comment('added in migration 037');
        $table->integer('authorization_code')->after('authorized')->nullable()->comment('added in migration 037');
        $table->dateTime('authorization_code_date')->after('authorization_code')->nullable()->comment('added in migration 037');
      });
    }
  }

  public function down() {
    if(Capsule::schema()->hasTable($this->table)) {
      $table_name = $this->table;
      Capsule::schema()->table($this->table, function (Blueprint $table) use ($table_name) {
        if (Capsule::schema()->hasColumn($table_name, 'authorized')) {
          $table->dropColumn('authorized');
          $table->dropColumn('authorization_code');
          $table->dropColumn('authorization_code_date');
        }
      });
    }
  }
}
?>

And the models look more like this

<?php
namespace Models;

class Person extends BaseModel
{
    /**  
     * The table associated with the model.
     * 
     * @var string
     */
    protected $table = 'people';

    /**  
     * Primary key name.
     * 
     * @var string
     */
    public $primaryKey = 'person_id';

    /**  
     * Do not automatically manage timestamps by Eloquent
     * 
     * @var bool
     */
    public $timestamps = false;

    /**  
     * The attributes that should be cast to native types.
     * 
     * @var array
     */
    protected $casts = [
        'person_id' => 'integer',
        'organization_id' => 'integer',
        'person_type_id' => 'integer',
        'primary_site_id' => 'integer',
        'title' => 'string',
        'given_name' => 'string',
        'given_middle_name' => 'string',
        'family_name' => 'string',
        'email' => 'string',
        'address_1' => 'string',
        'address_2' => 'string',
        'address_3' => 'string',
        'city' => 'string',
        'state' => 'string',
        'postal_code' => 'string',
        'country_id' => 'integer',
        'extra_1' => 'string',
        'created_at' => 'datetime',
        'created_by' => 'integer',
        'conversion_id' => 'string'
    ];

    public function organization()
    {
        return $this->belongsTo(Organization::class, 'organization_id', 'organization_id');
    }

    public function documentCategories()
    {
        return $this->hasMany(DocumentCategory::class, 'person_id', 'person_id');
    }

    public function documents()
    {
        return $this->hasMany(Document::class, 'person_id', 'person_id');
    }

    public function employees()
    {
        return $this->hasMany(Employee::class, 'person_id', 'person_id');
    }

    public function eventPeoples()
    {
        return $this->hasMany(EventPerson::class, 'person_id', 'person_id');
    }

    public function groupPeoples()
    {
        return $this->hasMany(GroupPerson::class, 'person_id', 'person_id');
    }

    public function personPhones()
    {
        return $this->hasMany(PersonPhone::class, 'person_id', 'person_id');
    }

    public function users()
    {
        return $this->hasMany(User::class, 'person_id', 'person_id');
    }
}
?>

As you can see I also have a BaseModel that is the parent of all models that use a common set of functions. Being able to set this would also be nice.

I know some of these things are project specific, but thought I would show what I am using it for to see if you can improve things if it is useful.

Thanks, Ryein

in Solved by (160 points)
recategorized by

1 Answer

0 votes

Hello Ryein,

thank you for sharing your experiences and ideas.

Unfortunately, it seems that your use case is very specific. Current Eloquent support in Skipper is based on the native Laravel+Eloquent setup and if I understand correctly, the standalone Illuminate Eloquent together with CI behaves slightly different. I believe by CI3/4 you're meaning CodeIgniter, right? Sorry to ask, but I'm not Laravel or CI expert.

The problem probably is the different syntax than Laravel Eloquent.

Altought it can look simillar, based on what you wrote it's completely different framework. This usually means that we have to implement it as a standalone support. Also, you're mentioning that you're using CI3 altought CI4 is already released. In case we will decide to implement CI+Eloquent, we will be able to implement only the only latest version. Unfortuantely, we don't have capacity to support also previous versions of the frameworks.

Regarding your question about base and derived classes, this is something we can't change. Because Eloquent doesn't use any structured langauge to define ORM (like XML,YML or annotations) we have to export whole php file with the definition during every export. We're not able to update Php definitions in the existing code. Because of that we decided to use base&derived classes so user can edit derived class and Skipper the base class.

All this means that currently we're not able to update Skipper in the way you would need. Maybe we will implement CI+Laravel support later when more users will be interested in this integration. But as I wrote, it will be support only for the latest version of the framework.

Thanks for understanding.

by Skipper developer (141k points)