arlx/repository-generator

Installs: 272

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/arlx/repository-generator

v3.0.24 2025-10-20 14:46 UTC

README

Latest Version on Packagist Total Downloads License

Table of Contents

    <li><a href="#features">Features</a></li>
    <li>
        <a href="#getting-started">Getting started</a>
        <ul>
            <li><a href="#installation">Installation</a></li>
        </ul>
    </li>
    <li>
      <a href="#usage">Usage</a>
      <ul>
        <li><a href="#generating-models">Generating models</a></li>
        <li><a href="#generating-repositories">Generating repositories</a></li>
        <li><a href="#generating-controllers">Generating controllers</a></li>
        <li><a href="#dependency-injection">Dependency Injection</a></li>
      </ul>
    </li>
    <li><a href="#auto-binding">Auto binding</a></li>
    <li><a href="#contributing">Contributing</a></li>
    <li><a href="#license">License</a></li>
    

Features

With this package you can generate models, repositories, and controllers using custom artisan commands.
The repository generator will also bind interfaces automatically to the Laravel Service Container for dependency injection.

Installation

Require the Laravel Repository Generator with composer.

composer require arlx/repository-generator

Usage

Generating models

Run the following command to generate a model:

php artisan geek:model User

This command will generate the following file:

app\Models\User.php

You can also include optional flags:

  • -m or --migration – generate a migration
  • -r or --resource – generate a resource controller
  • --repo – generate repository & interface
  • -a or --all – generate all of the above at once

Example:

php artisan geek:model User -mr --repo

Or simply:

php artisan geek:model User --all

The generated model structure looks like this:

<?php

namespace App\Models;

use App\Traits\HasUUID;
use Askedio\SoftCascade\Traits\SoftCascadeTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Wildside\Userstamps\Userstamps;

class User extends Model
{
    use HasFactory, SoftDeletes, SoftCascadeTrait, Userstamps, HasUUID;

    protected $guarded = [
        'id',
        'id_hash'
    ];

    protected $casts = [
        'created_at' => 'string',
        'updated_at' => 'string',
        'deleted_at' => 'string',
    ];

    protected $softCascade = [];
}

Generating repositories

Run the following command:

php artisan geek:repository UserRepository

This example will generate the following files:

app\Repositories\UserRepository
app\Interfaces\UserInterface

Generating controllers

Run the following command:

php artisan geek:controller Api/UserController --swagger-api=/api/master/user

note: --swagger-api is optional and will generate swagger tags and path

This example will generate the following file:

app\Http\Api\UserController

Dependency Injection

Next we have to inject the interface into the constructor of our controller.
For this example we will use the UserController.

<?php

namespace App\Http\Controllers;

use App\Repositories\UserInterface;

class UserController extends Controller
{
    public function __construct(
        private UserInterface $userRepository
    ) {}

    // your controller functions
}

Auto binding

The package will automatically bind the repository interfaces with the implementations,
so you can directly inject the interface into your controllers.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

The MIT License (MIT).