Download the PHP package okaybueno/laravel-repositories without Composer

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

IMPORTANT ❗

This package has been discontinued and it won't receive any other updates. If you're using it please consider migrating to another solution – or fork it and depend on your own version of package.

Using the repository pattern on Laravel does not feel good anymore. Laravel has evolved in a great way that made me embrace Eloquent at its maximum level. Comparing what Eloquent offers out of the box versus its implementation via the repository pattern, I found out that adding this intermediate layer ends up in providing yet one more layer to maintain that provides no value whatsoever to the final product or even during the process of development. I was wrong and I'm happy to be back to full Eloquent use.


Laravel Repositories

A package that provides a neat implementation for integrating the Repository pattern with Laravel & Eloquent.

Latest Version on Packagist Quality Score Total Downloads

Disclaimer

This package was originally released here, but since the future of that package is not clear, it has been forked and re-worked under this repository.

Goal

Working with repositories can provide a great way to not only decouple your code but also separate concerns and isolate stuff, as well as separate and group responsibilities. Most of the time we will perform really generic actions on our database tables, like create, update, filter or delete.

However, using repositories is not always a good idea, specially with Laravel and its ORM, Eloquent, as it -sometimes- forces you to give up some great features in favor of better architecture (it depends). For some projects this may be an overkill and therefore is up to the developer to see if this level of complexity is needed or not.

This package aims to provide a boilerplate when implementing the Repository pattern on Laravel's Eloquent ORM. The way it provides it it's using a RepositoryInterface and a basic Repository implementation that is able to work with Eloquent models, providing basic methods that will cover 85% if the Database operations that you will probably do in your application.

Installation

  1. Install this package by adding it to your composer.json or by running composer require okaybueno/laravel-repositories in your project's folder.
  2. For Laravel 5.5 the Service provider is automatically registered, but if you're using Laravel 5.4, then you must add the provider to your config/app.php file: OkayBueno\Repositories\RepositoryServiceProvider::class
  3. Publish the configuration file by running php artisan vendor:publish --provider="OkayBueno\Repositories\RepositoryServiceProvider"
  4. Open the configuration file (config/repositories.php) and configure paths according to your needs.
  5. Ready to go!

Usage

To start using the package, you just need to create a folder where you will place all your repository interfaces and the repository implementations and extend every single repository from the EloquentRepository class offered by the package.

The Eloquent model to be handled by the repository that you have created must also be injected via the Repo constructor.

The package then will try to load all the repository interfaces and bind them to a repository implementation according to the parameters specified in the config/repositories.php file.

Examples

NOTE: Although the package includes a generator, please read all the docs carefully as some things may look just "magic".

Let's consider we will have all our repositories in a folder called "Repositories", under a folder called "MyWebbApp" inside the "app" folder: app/MyWebApp/Repositories.

At the root of this folder we'll have all our interfaces following the next name convention: [RepositoryName]Interface.php

NOTE: It does not really matter the name that we use as long as we use "Interface" as suffix. This is important because the auto binder will try to find all files matching this pattern.

Inside this Repositories folder, we must have another folder called Eloquent, that will contain all our implementations for the repositories, following the next name convention: [RepositoryName].php.

We should have a structure like this:

Let's see what the UserRepositoryInterface.php and the UserRepository.php would have.

Now we need to configure the config/repositories.php file to match our paths and namespace:

All the parameters are properly explained in the file.

Now the repository is ready to be used and injected in other services or controllers:

NOTE: This example assumes that you have configured your composer.json to autoload the files on app/MyApp with the MyApp namespace.

Methods shipped by default.

The repository package offers a series of methods by default. These are:

Criteria

To avoid having our repository full of methods like findActiveUsers(), findActiveUsersOlderThan( $date ) and so on, we'll be using Criteria to apply filters to our searches or queries.

A Criteria is just a PHP Class that implements the CriteriaInterface provided by this package and that operates on the Eloquent model to apply the Query or set of queries that we want to apply for an specific search.

To create your own criterias, place them wherever you want and make them implement the CriteriaInterface provided.

For instance: Imagine we have an application where users can register via Facebook, Twitter or email. We would need to retrieve all users based on the method they used for registering. We would have a criteria like this:

Now in your services or controllers you can use this criteria like this:

We could even chain different criterias:

Criterias shipped by default

For more complex queries, a custom Criteria must be created.

And now let's jump directly into the cool stuff that will save some time in your end...

Generators!

Yeah, creating all those files, link them up, inject models and so on it's a bummer. Also for me. So I create a generator that creates the interface and the Eloquent implementation (basic) for our models. Cool, huh?

There are 2 generators provided: for repositories and for criteria

Repositories

Just execute php artisan make:repository Namespace\\ModelName --implementation=eloquent

Being ModelName the name of the model (class) that you want to generate the repository for. This will generate an interface for this repository, an eloquent implementation implementing that interface and will also inject the model to the repository. The files will be placed in the directory that you configure in your repositories.php config file, and will also have the namespace specified there. You can specify the implementation that you want to use, although for now just Eloquent is supported out of the box.

Criteria

Execute php artisan make:criteria Namespace\\ClassName --implementation=eloquent

This will generate a criteria, using the parameters configured in your repositories.php config file. Additionally, if you want to place the criteria inside a specific folder (inside the one already configured), you can specify that as an option to the command: php artisan make:criteria Accounts\\FilterByCreationDate.

Play a bit around and see how they behave when you pass different parameters!

Generators do lot of magic, but they are also descriptive with errors, so if it fails, just pay attention to the error ;D.

Traits

There are some functions included that do not necessarily need to be included in all repositories but that depend on the model injected. These are the traits available for the different types of entities involved:

Repositories

You can also manually specify which repositories should be mapped by this engine. All the repositories which are not explicitly mapped will be mapped to the default driver (eloquent):

Of course, you can use the generators to create criterias and repositories:

Changelog

v1.0.7:
v1.0.6:
v1.0.5:
v1.0.4:
v1.0.3:
v1.0.2:
v1.0.1:
v1.0.0:

Credits

Bugs & contributing

To-dos

License

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


All versions of laravel-repositories with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
illuminate/config Version >=6.0.0
illuminate/database Version >=6.0.0
illuminate/console Version >=6.0.0
illuminate/pagination Version >=6.0.0
illuminate/filesystem Version >=6.0.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 okaybueno/laravel-repositories contains the following files

Loading the files please wait ....