You can generate laravel repository class and interface using php artisan make:repository Category/CategoryRepository --model=Category.It will generate CategoryRepository class and CategoryRepositoryInterface inside the app/Repositories/Category folder.This package is developed based on the Spatie Laravel Package Skeleton.
You can install the package via composer:
composer require thantzin-soe/laravel-repository-generator
After installing via composer,you can generate scaffolding by running
php artisan make:repository Category/CategoryRepository --model=Category
You can add your bindings to your AppServiceProvider or you can a create a new service provider with php artisan make:provider RepositoryServiceProvider
(don't forget to add it in the providers array inside of config\app.php
) and add the bindings in the register()
method, here is the example.
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Repositories\Category\CategoryRepositoryInterface;
use App\Repositories\Category\CategoryRepository;
/**
* Class RepositoryServiceProvider
* @package App\Providers
*/
class RepositoryServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->bind(CategoryRepositoryInterface::class, CategoryRepository::class);
}
}
composer test
Any contributions are welcome.