Download the PHP package mattb-it/larepo without Composer

On this page you can find all versions of the php package mattb-it/larepo. 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 larepo

Larepo - Laravel Repository

Test build Latest version License

đź“„ Online Documentation

Introduction

This package is designed to help developers organize their code by offering a simplified approach to implementing the Repository Pattern in Laravel. While it doesn’t follow the pattern in its purest form, it provides a practical solution that aligns well with Laravel’s architecture. Eloquent, being as powerful as it is, handles many database interactions behind the scenes, making a strict Repository Pattern not really useful. Instead, this package focuses on helping you structure your code more effectively without adding complexity.

With this package, you’ll find it easier to apply SOLID principles, search through your codebase for operations like querying, deleting, or saving models, and simplify the way you manage models by introducing DTOs (Data Transfer Objects). It’s especially useful for intermediate developers looking to build clean, maintainable applications while keeping things simple.

Getting started

Installation

To install Larepo via Composer, run the following command:

Generate repository

Laravel projects typically include a User model by default. Let's generate a UserRepository using Larepo's artisan command:

This command will create a UserRepository class in app/Repositories/UserRepository.php:

Generate model DTO

After generating the UserRepository, the next step is to create a corresponding DTO (Data Transfer Object) for the User model. The DTO is necessary for using the save method.

This command generates the UserDTO class in app/DTO/Models/UserDTO.php:

Now that you've generated the UserDTO, you can populate it with the model's attributes. This will make saving the model easier. Here's an example DTO for the User model:

Attribute enum

The Attribute enum allows you to control whether a model's attribute should be updated or left unchanged. This is particularly useful when handling user input. For instance, if the request doesn't contain the name field, you can pass Attribute::UNDEFINED to signal that the attribute should not be modified, rather than setting it to null.

Here's an example that demonstrates how this works:

In this example, if the name parameter is absent from the request, Attribute::UNDEFINED is passed. This tells the save method that the name field should not be updated. Without this enum, passing a missing parameter could inadvertently set the field to null.

Methods

Larepo provides several methods to simplify common operations like querying, saving, and deleting models.

find

The find method retrieves a specific model by its primary key (usually id) or by another attribute:

If the model is not found, the method returns null.

findOrFail

Similar to find, but throws a ModelNotFoundException if the model is not found:

all

The all method retrieves all models from the database:

query

The query method allows you to create a query builder instance, which you can use to apply conditions:

delete

The delete method deletes the specified model instance from the database. It returns a bool indicating success or failure:

save

The save method creates or updates a model using a DTO that implements ModelDTOInterface. Before using this method, ensure that you've generated the model's DTO by running the php artisan larepo:make:dto User command.

You can also execute this method without model parameter to create a new model:

This method returns the created/updated model instance.


All versions of larepo with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/database Version ^11.27
illuminate/support Version ^11.27
illuminate/console Version ^11.27
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 mattb-it/larepo contains the following files

Loading the files please wait ....