Download the PHP package duardaum/laravel-repository without Composer

On this page you can find all versions of the php package duardaum/laravel-repository. 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-repository

Laravel Repository

A simple Repository and Service layer for Laravel and Lumen Applications.


Features


Summary


Compatibility

Version PHP Dependency Version
Laravel/Lumen 8.* 8.0 prefer-stable
Laravel/Lumen 8.* 8.1 prefer-lowest, prefer-stable
Laravel/Lumen 9.* 8.0, 8.2 prefer-stable
Laravel/Lumen 9.* 8.1 prefer-lowest, prefer-stable
Laravel/Lumen 10.* 8.1, 8.2, 8.3 prefer-lowest, prefer-stable
Laravel/Lumen 11.* 8.2, 8.3, 8.4 prefer-stable
Laravel 12.* 8.2, 8.3, 8.4 prefer-lowest, prefer-stable

Installation

Use composer to install the package:

Configuration

In your Laravel/Lumen application, create a new Service Provider.
This Service Provider will be the place where you'll register all your Repositories.
You can register your repositories in the AppServiceProvider if you wish, but to keep things separated and for the possibility the Service Provider be very large, we recommend putting them separated.

And then, register the new Service Provider in your application:

On Lumen:

On Laravel:

Usage

The Repository Pattern is a design pattern that became very popular over the years.
It's a very nice and good way to organize data access and logic in one place, keeping other parts of your application responsible for what they do best,
especially if you are using other Design Patterns like S.O.L.I.D and Clean Code.
With this in mind, we created this very simple but yet powerful package, for you to centralize all your data access in a very simple way.

Model, Repository & Interface

Let's suppose that we have a table called messages with this structure, and we'll run some SQL commands on it:

First, let's create a Model:

Then, let's create an Interface for the Repository. All interfaces MUST extend from BaseRepositoryInterface:

And let's create the Repository. All repositories MUST extend from BaseRepository and implement an interface that was extended from BaseRepositoryInterface.
For the repository to know what table it should run the queries on, we need to inform a Model for the Repository:

P.S.: Some people do not like to use Interfaces on repositories. If it's your case, just dont and all be fine too!

Finally, let's register the repository to be used in the application:

This structure with Repository & Interface is very helpful if you need to make a different implementation of the same repository.
The contract of the repository stays the same and does not affect your application, needing to go in one place to replace all.

Basic usage

You can inject the Interface in constructors/methods to instantiate the Repository or use the Service Container to do it:

Create, Update and Delete

To make these operations is very simple:

Create via CSV file (import file)

One of the common challange we face in our day-in-day work, is importing a large number of register via CSV files to the database. \ Some time, we dont need nothing fancy, just a simple but yet powerfull way to import the file, where we can customize witch column on CSV file we want to import for certain table column. \ Thinking of that, we create an opinionated way to do this kind of work in a simple, fast and using the minimum amount of memory possible.

This type of task can be done in several ways, but the way your environment is configured and the resources are available will influence performance!

For this task, we create the importFile method on the BaseRepository, that has 4 parameters:

The method return the number of chunk inserted on database!

Import: Basic (no $rowGenerate)

Import: Advanced (with $rowGenerate)

For more example, look into our test suite!

Read

One of the greatest features of this package is the possibility to read data from different states (active, deactivated or both) in the same operation with minimal effort. By default, the repository will get data only for active records (newQuery). To get from trash (deactivated) or both, there is an easy way to do it:

Custom methods

To create a custom method on repository is very simple, and you can take advantage of the built-in methods of the base repository to do it:

And you can create a custom method, taking into consideration the query context chosen by user:

Available Methods

The BaseRepository provides sereval methods out of the box that you can use easily like:

You can extend your repository with custom methods as needed. For more available methods, you can find here . \ Yet, you can use the Eloquent methods strait from repository if you need to via the builder method:

You can see how to use all methods looking in our tests .

Testing

To ensure your repositories are working as expected, you can write tests using Laravel's built-in testing tools. Example:

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

How to contribute:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request.

Please make sure to update tests as appropriate.

License

MIT


All versions of laravel-repository with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
illuminate/database Version >=8.0
illuminate/contracts Version >=8.0
illuminate/support Version >=8.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 duardaum/laravel-repository contains the following files

Loading the files please wait ...