Search by

immachakata / ci4-facades

immachakata

Use laravel like facades and functions for creating migration files, among other things

Package info

github.com/immachakata/ci4-facades

pkg:composer/immachakata/ci4-facades

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-11-12 19:42 UTC

This package is auto-updated.

Last update: 2026-11-12 19:44:41 UTC


README

Packagist Version Packagist Downloads Packagist License A lightweight PHP package for CodeIgniter 4 that brings clean, expressive, Laravel-like traits and facades to your project—starting with database migrations and logging.

Requirements

  • PHP >= 7.4 or 8.0+
  • CodeIgniter 4.x

Installation

Install the package via Composer:

composer require immachakata/ci4-facades

Usage

Migrations (Schema & Ci4Facades Trait)

You can use either the Schema facade directly or the IsaacMachakata\Ci4Facades trait inside your CodeIgniter 4 migration classes:

<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;
use IsaacMachakata\Ci4Facades;
use IsaacMachakata\Ci4Facades\Blueprint;
use IsaacMachakata\Ci4Facades\Schema;

class CreateUsersTable extends Migration
{
    use Ci4Facades;

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
            $table->softDeletes();
        });
    }

    public function down()
    {
        Schema::dropIfExists('users');
    }
}

Or using the trait helper methods ($this->create(), $this->dropIfExists()):

$this->create('posts', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('user_id');
    $table->string('title');
    $table->text('body')->nullable();
    $table->timestamps();
    $table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
});

Available Blueprint Column Methods

  • $table->id('id') / $table->increments('id')
  • $table->string('name', 255) / $table->char('code', 10)
  • $table->text('description') / $table->longText('content')
  • $table->integer('votes') / $table->bigInteger('views') / $table->unsignedBigInteger('user_id')
  • $table->boolean('is_admin') / $table->tinyInteger('status')
  • $table->decimal('amount', 8, 2) / $table->float('rating', 8, 2)
  • $table->date('birth_date') / $table->dateTime('published_at') / $table->timestamp('logged_at')
  • $table->timestamps() / $table->softDeletes()
  • $table->json('options') / $table->enum('status', ['draft', 'published'])
  • Modifiers: ->nullable(), ->default($val), ->unsigned(), ->unique(), ->primary(), ->index(), ->comment('...'), ->after('col'), ->first()

Logging (Log Facade)

Instead of calling CodeIgniter's procedural log_message('info', 'message') helper, you can use the expressive Log facade:

use IsaacMachakata\Ci4Facades\Log;

// Instead of: log_message('info', 'User logged in');
Log::info('User logged in');

// Other log levels:
Log::error('Something went wrong');
Log::debug('Debugging payload data');
Log::warning('Disk space is running low');
Log::critical('Database connection failed');

Roadmap

  • Migration traits (use IsaacMachakata\Ci4Facades)
  • Logging facade (Log::info("message"))
  • Expressive Schema & Blueprint builder helpers
  • Additional CodeIgniter 4 service facades

Contributing

Contributions, issues, and feature requests are welcome! Feel free to open an issue or submit a pull request.

Author

License

This package is open-sourced software licensed under the MIT license.