PHPackages                             surazdott/laravel-repository - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. surazdott/laravel-repository

ActivePackage[Utility &amp; Helpers](/categories/utility)

surazdott/laravel-repository
============================

Laravel repository design pattern with service and interface.

v1.0.1(2y ago)6220↓100%MITPHPPHP ^8.1

Since Mar 15Pushed 2y agoCompare

[ Source](https://github.com/surazdott/laravel-repository)[ Packagist](https://packagist.org/packages/surazdott/laravel-repository)[ RSS](/packages/surazdott-laravel-repository/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Laravel Repository Design Pattern
=================================

[](#laravel-repository-design-pattern)

Introduction
------------

[](#introduction)

Laravel Repository Design Pattern package provides an overview of the design pattern used in a Laravel service and repository structure. The primary goal of this pattern is to separate concerns, improve code organization, and enhance maintainability.

Repository Pattern Components
-----------------------------

[](#repository-pattern-components)

- Service Layer: This layer contains the business logic of your application. It abstracts the application's functionality from the controller, promoting better separation of concerns.
- Repository Layer: The repository acts as an interface to interact with the database. It abstracts the database operations from the service layer, making it easy to switch to a different data source without affecting the business logic.

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.1+](https://php.net/releases/)**

First, install package via the [Composer](https://getcomposer.org/) package manager:

```
composer require surazdott/laravel-repository
```

#### Generating Classes

[](#generating-classes)

You can also generate repository class indivisually or can be generated with options.

#### `Basic Commands`

[](#basic-commands)

```
// Generate repository class
php artisan make:repository UserRepository

// Generate repository with service
php artisan make:repository UserRepository --service

// Generate repository with interface
php artisan make:repository UserRepository --interface

// Generate repository with interface and service
php artisan make:repository UserRepository --all

// Generate service class
php artisan make:repository-service UserService

// Generate interface class
php artisan make:repository-interface UserRepositoryInterface
```

To find help and options

```
php artisan make:repository --help
```

Basic usages
------------

[](#basic-usages)

As the software development industry continues to evolve, there has been a focus on improving code maintainability, leading to modifications in design patterns.

#### `Base Class`

[](#base-class)

- `use SurazDott\Repositories\BaseRepository;`
- `use SurazDott\Services\BaseService;`

Let's look at a simple example:

#### Repository Interface

[](#repository-interface)

Make your initial repository interface first.

```
php artsian make:repository-interface UserRepositoryInterface

```

`App\Repositories\Interfaces\UserRepositoryInterface.php`

```
