Download the PHP package czim/laravel-repository without Composer

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

Latest Version on Packagist Latest Stable Version SensioLabsInsight

Repository setup inspired by the Bosnadev/Repository package. This package is an extended, adjusted (but entirely independent) version of that, with its own interfaces.

One major difference to the Bosnadev repository is that this one is able to deal with repeated and varying calls to the same repository instance, without breaking down or undesirable repeated application of Criteria. You can instantiate a repository once and do anything with it in any order, and both queries and model manipulation methods will keep working.

Among the added functionality is the ability to override or 'temporarily' set and remove Criteria, post-processing models after retrieval.

I'm well aware that there is much to say against using Repositories like this (and the repository pattern in general), but I find they have their uses. I prefer using them to make for easier unit testing in large projects.

Note: I recommand against using this package. I'm making some updates for my personal legacy projects, but I consider this approach to be a serious antipattern (at least with Eloquent).

Version Compatibility

Laravel Package
5.1 1.0
5.2 1.2
5.3 1.2
5.4 to 5.8 1.4
6.0 2.0
7.0, 8.0 2.1
9.0 3.0, 4.0

Warning

Version 4.0 has many breaking changes. Refer to the Changelog for details.

Install

Via Composer

If you want to use the repository generator through the make:repository Artisan command, add the RepositoryServiceProvider to your config/app.php:

Publish the repostory configuration file.

Basic Usage

Simply extend the (abstract) repository class of your choice, either Czim\Repository\BaseRepository, Czim\Repository\ExtendedRepository or Czim\Repository\ExtendedPostProcessingRepository.

The only abstract method that must be provided is the model method (this is just like the way Bosnadev's repositories are used).

Base- and Extended Repositories

Depending on what you require, three different abstract repository classes may be extended:

Using the repository to retrieve models

Apart from the basic stuff (inspired by Bosnadev), there are some added methods for retrieval:

Every retrieval method takes into account the currently active Criteria (including one-time overrides), see below.

For the ExtendedPostProcessingRepository goes that postprocessors affect all models returned, and so are applied in all the retrieval methods (find(), firstOrFail(), all(), allCallback, etc). The query() method returns a Builder object and therefore circumvents postprocessing. If you want to manually use the postprocessors, simply call postProcess() on any Model or Collection of models.

Handling Criteria

Just like Bosnadev's repository, Criteria may be pushed onto the repository to build queries. It is also possible to set default Criteria for the repository by overriding the defaultCriteria() method and returning a Collection of Criteria instances.

Criteria may be defined or pushed onto the repository by key, like so:

This allows you to later remove the Criteria by referring to its key:

To change the Criteria that are to be used only for one call, there are helper methods that will preserve your currently active Criteria. If you use any of the following, the active Criteria are applied (insofar they are not removed or overridden), and additional Criteria are applied only for the next retrieval method.

Note that this means that only Criteria that have keys can be removed or overridden this way. A CriteriaKey Enum is provided to more easily refer to the standard keys used in the ExtendedRepository, such as 'active', 'cache' and 'scope'.

Configuration

No configuration is required to start using the repository. You use it by extending an abstract repository class of your choice.

Extending the classes

Some properties and methods may be extended for tweaking the way things work. For now there is no documentation about this (I will add some later), but the repository classes contain many comments to help you find your way (mainly check the ExtendedRepository class).

Traits

Additionally, there are some traits that may be used to extend the functionality of the repositories, see Czim\Repository\Traits:

I've added these mainly because they may help in using the repository pattern as a means to make unit testing possible without having to mock Eloquent models.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-repository with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9.0 || ^10.0 || ^11.0
illuminate/database Version ^9.0 || ^10.0 || ^11.0
myclabs/php-enum Version ^1.7
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 czim/laravel-repository contains the following files

Loading the files please wait ....