PHP code example of kraicdesign / eloquent-bundle

1. Go to this page and download the library: Download kraicdesign/eloquent-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kraicdesign / eloquent-bundle example snippets


// config/bundles.php
return [
    // ...
    Kraicdesign\EloquentBundle\EloquentBundle::class => ['all' => true],
];

use Illuminate\Database\ConnectionInterface;

final class UserRepository
{
    public function __construct(private readonly ConnectionInterface $db)
    {
    }

    public function findByEmail(string $email): ?object
    {
        return $this->db->table('users')->where('email', $email)->first();
    }
}

use Kraicdesign\EloquentBundle\Contract\DatabaseConnection;

final class TagRepository
{
    public function __construct(private readonly DatabaseConnection $db)
    {
    }

    public function supportsVisibility(): bool
    {
        return $this->db->getSchemaBuilder()->hasColumn('pc_tags', 'show_to_all_pcs');
    }
}

use Illuminate\Database\Eloquent\Model;

final class User extends Model
{
    protected $table = 'users';
}

User::query()->where('active', true)->get();

// database/migrations/2026_01_01_000000_create_users_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

return new class extends Migration {
    public function up(): void
    {
        $this->schema()->create('users', function (Blueprint $table): void {
            $table->id();
            $table->string('email')->unique();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        $this->schema()->dropIfExists('users');
    }
};
bash
php bin/console database:migrate
php bin/console database:migrate:rollback