Download the PHP package mobileka/scope-applicator-laravel without Composer

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

Build Status Code Climate Coverage Status

If you're looking for a version which works with Laravel 4.x.x and 5.0.x, click here.

ScopeApplicator brings an elegant way of sorting and filtering data to your Laravel projects.

Overview

ScopeApplicator is an easy and logical way to achieve something like this:

/posts – returns a list of all posts

/posts?recent – returns only recent posts

/posts?author_id=5 – returns posts belonging to an author with an id=5

/posts?author_id=5&order_by_title=desc&status=active – returns only active posts belonging to an author with an id=5 and sorts them by a title in a descending order

Requirements

Laravel ~5.1

Installation

composer require mobileka/scope-applicator-laravel 1.1.*

Usage (with Models)

Make sure you are familiar with Laravel's query scopes before you dive in

Let's learn by example. First of all, we'll implement an author_id filter for posts table.

Please note that this is going to be a basic example and it's not the most optimal way of doing things ;)

These are steps required to achieve this:

  1. Create a basic PostController which outputs a list of posts when you hit /posts route
  2. Create a userId scope in the Post model (and it has to extend the Mobileka\ScopeApplicator\Laravel\Model class)
  3. Tell ScopeApplicator that this scope is available and give it an alias
  4. Visit /posts?author_id=1 and enjoy the result

Ok, let's cover these step by step.

— The PostController:

— The Post model:

Note that it extends Mobileka\ScopeApplicator\Laravel\Model

— Now we have to replace Post::all() in our controller with Post::handleScopes() and tell this mehotd which scopes are available for filtering:

Take a note that 'userId' matches the name of the scope we've created in the Post model (scopeUserId).

At this moment you can add some dummy data to your posts table and make sure that you can filter it by hitting the following route: /posts?userId=your_number

But, as we wanted author_id instead of userId, let's create an alias for this scope:

— That's it! Now you can visit /posts?author_id=x and check the result.

alias is only one of the many available scope configuration options. These are described in ScopeApplicator's documentation.

A better usage scenario (with Repositories)

ScopeApplicator can also be used with Repositories. It was actually designed to be used this way.

To achieve this, your repository has to extend the Mobileka\ScopeApplicator\Laravel\Repository class.

The ScopeApplicator is already attached to this class, so you'll have a new applyScopes() method available in repositories extending it.

Let's see an example BaseRepository before we extend the aforementioned class:

DataProvider is typically an instance of a Model.

And now what it looks like with ScopeApplicator:

Pay closer attention to all method. Now it accepts an array of scopes (the same array we were passing to Model::handleScopes()).

Instead of directly calling all on our DataProvider, we now use applyScopes() method which accepts a DataProvider instance as a first argument and a scope configuration array as a second.

Contributing

If you have noticed a bug or have suggestions, you can always create an issue or a pull request (use PSR-2). We will discuss the problem or a suggestion and plan the implementation together.

License

ScopeApplicator is an open-source software and licensed under the MIT License.


All versions of scope-applicator-laravel with dependencies

PHP Build Version
Package Version
Requires mobileka/scope-applicator Version 1.1.*
illuminate/log Version ~5.1
illuminate/http Version ~5.1
illuminate/database Version ~5.1
illuminate/support Version ~5.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 mobileka/scope-applicator-laravel contains the following files

Loading the files please wait ....