A simple Laravel package to create repository, using artisan commands
visiarch/laravel-repository is a Laravel package for a simple laravel package to create repository, using artisan commands.
It currently has 0 GitHub stars and 16 downloads on Packagist (latest version 1.0.0).
Install it with composer require visiarch/laravel-repository.
Discover more Laravel packages by visiarch
or browse all Laravel packages to compare alternatives.
Last updated

A Simple Package to create repositories, using artisan commands in laravel.
This package extends the make: commands to help you easily create repository classes in Laravel 9+.
Repository is a design pattern used to manage data access logic. It provides abstraction between the application and data access layers, such as databases.
composer require visiarch/laravel-repository
Once it is installed, you can use any of the commands in your terminal.
Repositories are used to separate data access logic from business logic, allowing developers to change how data is stored and retrieved without affecting business logic.
php artisan make:repository {name} --i
php artisan make:repository {name}
php artisan make:repository PostRepository --i
app/Repositories/Interfaces/PostRepositoryInterface.php
<?php
namespace App\Repositories\Interfaces;
/**
* Interface PostRepositoryInterface
*
* This interface defines the methods for the PostRepository class.
*/
interface PostRepositoryInterface
{
//
}
app/Repositories/PostRepository.php
<?php
namespace App\Repositories;
use App\Repositories\Interfaces\PostRepositoryInterface;
/**
* Class PostRepository
*
* @package App\Repositories
*/
class PostRepository implements PostRepositoryInterface
{
//
}
app\Providers\AppServiceProvider
public function register(): void
{
//
$this->app->bind(
\App\Repositories\Interfaces\PostRepositoryInterface::class,
\App\Repositories\PostRepository::class
);
}
php artisan make:repository PostRepository
app/Repositories/PostRepository.php
<?php
namespace App\Repositories;
/**
* Class PostRepository
*
* @package App\Repositories
*/
class PostRepository
{
//
}
<?php
namespace App\Repositories\Interfaces;
use App\Models\Post;
class PostRepository implements PostRepositoryInterface
{
public function store(array $data): Post;
}
<?php
namespace App\Repositories;
use App\Models\Post;
class PostRepository implements PostRepositoryInterface
{
protected $post;
public function __construct(Post $post){
$this->post = $post;
}
public function store(array $data): Post
{
return $this->post->create($data);
}
}
<?php
namespace App\Repositories;
use App\Models\Post;
class PostRepository
{
protected $post;
public function __construct(Post $post){
$this->post = $post;
}
public function store(array $data): Post
{
return $this->post->create($data);
}
}
<?php
namespace App\Repositories;
use App\Models\Post;
use App\Repositories\Interfaces\PostServiceInterface;
use App\Http\Requests\PostRequest;
class PostController extends Controller
{
protected $postService;
public function __construct(PostServiceInterface $postService)
{
$this->postService = $postService;
}
public function store(PostRequest $request): RedirectResponse
{
$data = $request->validated();
$this->postService->store($data);
return redirect()->route('posts.index')->with('success', __('post created'));
}
}
Just change PostRepositoryInterface to PostRepository if you are implementing without interface
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
Why not star the github repo? I'd love the attention! Why not share the link for this repository on any social media? Spread the word!
Thanks! visiarch
The MIT License (MIT). Please see License File for more information.