Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ozan's avatar
Level 32

Repoist - Laravel 5 Repository Generator

Repoist

Laravel 5 repository generator.

Repoist

Usage

Step 1: Install Through Composer

composer require ozankurt/repoist --dev

Step 2: Add the Service Provider

You'll only want to use these generators for local development, so you don't want to update the production providers array in config/app.php. Instead, add the provider in app/Providers/AppServiceProvider.php, like so:

public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register('Kurt\Repoist\RepoistServiceProvider');
    }
}

Step 3: Publish and edit the configurations

Run php artisan vendor:publish from the console to configure the Repoist according to your needs.

Step 4: Run Artisan!

You're all set. Run php artisan from the console, and you'll see the new commands in the make:repository namespace section.

Examples

Repositories Without Schema

php artisan make:repository Task

Will output:

  • app/Repositories/Task/TaskRepository.php (contract)
  • app/Repositories/Task/EloquentTaskRepository.php

Repositories With Schema

php artisan make:repository Task -m

Will output:

  • app/Repositories/Task/TaskRepository.php (contract)
  • app/Repositories/Task/EloquentTaskRepository.php
  • app/Task.php

Configurations

If somehow you cannot publish the config/repoist.php from artisan here you can copy and use it.

<?php

return [

    /**
     * Default path of repositories in `app` folder.
     * In this case:
     *      app/Repositories
     */
    'path' => 'Repositories',

    /**
     * Default path of models in laravel is the `app` folder.
     * In this case:
     *      app/
     */
    'model_path' => '',

    /**
     * Configure the naming convention you wish for your repositories.
     */
    'fileNames' => [
        'contract' => '{name}Repository',
        'eloquent' => 'Eloquent{name}Repository',
    ],

];
0 likes
9 replies
RemiC's avatar

From your templates :


class {{class}} extends {{contract}}

You mean 'implements' ?

1 like
bobbybouwmann's avatar

Cool stuff ;) What is the next generator? Would be cool to have a generator to create a migration, a model, a controller, a repository and a request with one command :P

Ozan's avatar
Level 32

@JeffreyWay Already did that! Credits to him. :)

@bobbybouwmann But I will add the functionality to print you the code you need to paste to your ServiceProvider to bind the contracts to repositories.

luddinus's avatar

I'm making a package named Modulator

php artisan module:make user

// generates
app/Modules/User/User.php (model)
app/Modules/User/Entities/UserEntity.php (model contract, useful to bind routes)
app/Modules/User/Providers/UserServiceProvider.php 
app/Modules/User/Providers/UserRouteServiceProvider.php 
app/Modules/User/Providers/UserEventServiceProvider.php 
app/Modules/User/Database/Repositories/UserRepository.php app/Modules/User/Database/Repositories/UserRepositoryInterface.php 
app/Modules/User/Database/Mappers/UserMapper.php 
app/Modules/User/Database/Mappers/UserMapperInterface.php 
app/Modules/User/Http/Controllers/UserController.php 

for example when you enter to this route users/{user}

// show the user
public function (UserEntity $user)
{
    // route /users/1
    // automatically injects the user with ID 1 from UserRepository->getById(1);
}

Additional commands

php artisan module:observer user creating // created app/Modules/User/Observers/UserCreating.php

class UserCreating {

    public function __construct()
    {
        // 
    }

    public function handle(UserEntity $user)
    {
        // it listens to "eloquent.creating: App\Modules\User\User" which is fired by UserMapper
    }
}
php artisan module:request user UserCreateRequest

// generates a request in App\Modules\User\Http\Requests
// same with:
//    "php artisan module:middleware user IsAuthenticated
//    "php artisan module:controller user ProfileController
php artisan module:event UserRegisteredEvent --listener=SendEmailConfirmation

// generates the event and the listeners with the event "injected"
1 like
ddutra's avatar

Ozan, I will try you package. I am just now refactoring some code and will have to create a bunch os Repos. Thanks!

Fawwad's avatar

same instruction i fallowed for version 5.3 but i am unable to create Repositories using php artisan make:repository name-of-repository

ilkb's avatar

app/Contracts/Task/TaskRepository.php (contract) app/Repositories/Eloquent/EloquentTaskRepository.php app/Task.php (if needed)

it outputs this one.

please help

Please or to participate in this conversation.