Download the PHP package acacha/l5-repository without Composer

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

Laravel 5 Repositories

Laravel 5 Repositories is used to abstract the data layer, making our application more flexible to maintain.

Latest Stable Version Total Downloads Latest Unstable Version License Analytics Code Climate

See versions: 1.0.* / 2.0.*

Migrate to: 2.1

You want to know a little more about the Repository pattern? Read this great article.

Table of Contents

Installation

Composer

Execute the following command to get the latest version of the package:

Laravel

In your config/app.php add Prettus\Repository\Providers\RepositoryServiceProvider::class to the end of the providers array:

If Lumen

Publish Configuration

Methods

Prettus\Repository\Contracts\RepositoryInterface

Prettus\Repository\Contracts\RepositoryCriteriaInterface

Prettus\Repository\Contracts\CacheableInterface

Prettus\Repository\Contracts\PresenterInterface

Prettus\Repository\Contracts\Presentable

Prettus\Repository\Contracts\CriteriaInterface

Prettus\Repository\Contracts\Transformable

Usage

Create a Model

Create your model normally, but it is important to define the attributes that can be filled from the input form data.

Create a Repository

Generators

Create your repositories easily through the generator.

Config

You must first configure the storage location of the repository files. By default is the "app" folder and the namespace "App". Please note that, values in the paths array are acutally used as both namespace and file paths. Relax though, both foreward and backward slashes are taken care of during generation.

You may want to save the root of your project folder out of the app and add another namespace, for example

Additionally, you may wish to customize where your generated classes end up being saved. That can be accomplished by editing the paths node to your liking. For example:

Commands

To generate everything you need for your Model, run this command:

This will create the Controller, the Validator, the Model, the Repository, the Presenter and the Transformer classes. It will also create a new service provider that will be used to bind the Eloquent Repository with its corresponding Repository Interface. To load it, just add this to your AppServiceProvider@register method:

You can also pass the options from the command, since this command is just a wrapper.

To generate a repository for your Post model, use the following command

To generate a repository for your Post model with Blog namespace, use the following command

Added fields that are fillable

To add validations rules directly with your command you need to pass the --rules option and create migrations as well:

The command will also create your basic RESTfull controller so just add this line into your routes.php file and you will have a basic CRUD:

When running the command, you will be creating the "Entities" folder and "Repositories" inside the folder that you set as the default.

Done, done that just now you do bind its interface for your real repository, for example in your own Repositories Service Provider.

And use

Alternatively, you could use the artisan command to do the binding for you.

Use methods

Find all results in Repository

Find all results in Repository with pagination

Find by result by id

Hiding attributes of the model

Showing only specific attributes of the model

Loading the Model relationships

Find by result by field name

Find by result by multiple fields

Find by result by multiple values in one field

Find by result by excluding multiple values in one field

Find all using custom scope

Create new entry in Repository

Update entry in Repository

Delete entry in Repository

Create a Criteria

Using the command

Criteria are a way to change the repository of the query by applying specific conditions according to your needs. You can add multiple Criteria in your repository.

Using the Criteria in a Controller

Getting results from Criteria

Setting the default Criteria in Repository

Skip criteria defined in the repository

Use skipCriteria before any other chaining method

Popping criteria

Use popCriteria to remove a criteria

Using the RequestCriteria

RequestCriteria is a standard Criteria implementation. It enables filters to perform in the repository from parameters sent in the request.

You can perform a dynamic search, filter the data and customize the queries.

To use the Criteria in your repository, you can add a new criteria in the boot method of your repository, or directly use in your controller, in order to filter out only a few requests.

Enabling in your Repository

Remember, you need to define which fields from the model can be searchable.

In your repository set $fieldSearchable with the name of the fields to be searchable or a relation to fields.

You can set the type of condition which will be used to perform the query, the default condition is "="

Enabling in your Controller

Example the Criteria

Request all data without filter by request

http://prettus.local/users

Conducting research in the repository

http://prettus.local/users?search=John%20Doe

or

http://prettus.local/users?search=John&searchFields=name:like

or

http://prettus.local/[email protected]&searchFields=email:=

or

http://prettus.local/users?search=name:John Doe;email:[email protected]

or

http://prettus.local/users?search=name:John;email:[email protected]&searchFields=name:like;email:=

Filtering fields

http://prettus.local/users?filter=id;name

Sorting the results

http://prettus.local/users?filter=id;name&orderBy=id&sortedBy=desc

Sorting through related tables

http://prettus.local/users?orderBy=posts|title&sortedBy=desc

Query will have something like this

http://prettus.local/users?orderBy=posts:custom_id|posts.title&sortedBy=desc

Query will have something like this

Add relationship

http://prettus.local/users?with=groups

Overwrite params name

You can change the name of the parameters in the configuration file config/repository.php

Cache

Add a layer of cache easily to your repository

Cache Usage

Implements the interface CacheableInterface and use CacheableRepository Trait.

Done , done that your repository will be cached , and the repository cache is cleared whenever an item is created, modified or deleted.

Cache Config

You can change the cache settings in the file config/repository.php and also directly on your repository.

config/repository.php

It is possible to override these settings directly in the repository.

The cacheable methods are : all, paginate, find, findByField, findWhere, getByCriteria

Validators

Requires prettus/laravel-validator. composer require prettus/laravel-validator

Easy validation with prettus/laravel-validator

For more details click here

Using a Validator Class

Create a Validator

In the example below, we define some rules for both creation and edition

To define specific rules, proceed as shown below:

Enabling Validator in your Repository

Defining rules in the repository

Alternatively, instead of using a class to define its validation rules, you can set your rules directly into the rules repository property, it will have the same effect as a Validation class.

Validation is now ready. In case of a failure an exception will be given of the type: Prettus\Validator\Exceptions\ValidatorException

Presenters

Presenters function as a wrapper and renderer for objects.

Fractal Presenter

Requires Fractal. composer require league/fractal

There are two ways to implement the Presenter, the first is creating a TransformerAbstract and set it using your Presenter class as described in the Create a Transformer Class.

The second way is to make your model implement the Transformable interface, and use the default Presenter ModelFractarPresenter, this will have the same effect.

Transformer Class
Create a Transformer using the command

This wil generate the class beneath.

Create a Transformer Class
Create a Presenter using the command

The command will prompt you for creating a Transformer too if you haven't already.

Create a Presenter
Enabling in your Repository

Or enable it in your controller with

Using the presenter after from the Model

If you recorded a presenter and sometime used the skipPresenter() method or simply you do not want your result is not changed automatically by the presenter. You can implement Presentable interface on your model so you will be able to present your model at any time. See below:

In your model, implement the interface Prettus\Repository\Contracts\Presentable and Prettus\Repository\Traits\PresentableTrait

There, now you can submit your Model individually, See an example:

You can skip the presenter at every visit and use it on demand directly into the model, for it set the $skipPresenter attribute to true in your repository:

Model Class
Implement Interface
Enabling in your Repository

Prettus\Repository\Presenter\ModelFractalPresenter is a Presenter default for Models implementing Transformable

Or enable it in your controller with

Skip Presenter defined in the repository

Use skipPresenter before any other chaining method

or


All versions of l5-repository with dependencies

PHP Build Version
Package Version
Requires illuminate/http Version ~5.0
illuminate/config Version ~5.0
illuminate/support Version ~5.0
illuminate/database Version ~5.0
illuminate/pagination Version ~5.0
illuminate/console Version ~5.0
illuminate/filesystem Version ~5.0
prettus/laravel-validation Version 1.1.*
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 acacha/l5-repository contains the following files

Loading the files please wait ....