Download the PHP package goodmanluphondo/laravel-service-repository-pattern without Composer

On this page you can find all versions of the php package goodmanluphondo/laravel-service-repository-pattern. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-service-repository-pattern

Laravel Service-Repository Pattern

Latest Stable Version Total Downloads License

A Laravel package that helps you implement the Service-Repository pattern in your Laravel applications. This package provides base classes and Artisan commands to quickly scaffold repositories, interfaces, and services following clean architecture principles.

Note: This package enforces separation of concerns between data access and business logic. Use it to maintain clean, testable, and maintainable code architecture.

This package includes the following features:

Installation

Require this package with composer:

Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Laravel without auto-discovery:

If you don't use auto-discovery, add the ServiceProvider to the providers list. For Laravel 11 or newer, add the ServiceProvider in bootstrap/providers.php. For Laravel 10 or older, add the ServiceProvider in config/app.php.

Publish the base files

After installation, publish the base files to your application:

This will publish:

Register the Repository Service Provider

After publishing, add the RepositoryServiceProvider (this is the published file that binds your repository interfaces) to your config/app.php (for Laravel 10 and older) or bootstrap/providers.php (for Laravel 11+):

Usage

Creating a Simple Service

Use the make:service command to create a new service class:

This creates app/Services/UserService.php.

Creating a Service with Repository Pattern

For services tied to a model, use the -R (or --repository) flag to scaffold the complete repository structure:

This command will:

  1. Create app/Interfaces/PostRepositoryInterface.php (or app/Interfaces/Posts/PostRepositoryInterface.php for sub-namespaced models)
  2. Create app/Repositories/PostRepository.php (or app/Repositories/Posts/PostRepository.php for sub-namespaced models)
  3. Create app/Services/PostService.php (or app/Services/Posts/PostService.php for sub-namespaced models)
  4. Automatically bind the interface to the repository in RepositoryServiceProvider

Important: The model must exist before running this command. The command supports both root models (app/Models/User.php) and sub-namespaced models (app/Models/Blog/Post.php).

Using Sub-namespaces

For services not tied to a model that need sub-namespace organization:

This creates app/Services/Integrations/PaymentService.php.

Generated Structure

When using the -R flag, the generated files follow this structure:

Repository Interface

Repository Implementation

Service

Available Repository Methods

The base repository provides these methods out of the box:

Method Description
query() Get a query builder instance
find($id) Find a model by ID (throws exception if not found)
findAll() Get all models
create(array $data) Create a new model
update($id, array $data) Update a model by ID
delete($id) Delete a model by ID
firstOrCreate(array $data) Get first matching model or create new one
firstWhere(string $column, $value) Get first model matching condition
where(string $column, $value) Add where condition to query
orderBy(string $column, string $direction = 'asc') Add order by to query

Example Usage in Controller

Requirements

License

This package is open-sourced software licensed under the MIT license.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


All versions of laravel-service-repository-pattern with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^12.0
illuminate/database Version ^12.0
illuminate/console Version ^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package goodmanluphondo/laravel-service-repository-pattern contains the following files

Loading the files please wait ....