Download the PHP package petrelli/scoped-controller without Composer

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

Scoped Controller

Scoped Controller is a very simple Laravel package (<80 LOC) that will allow you to build queries and cleanup your controllers by executing scopes based on request parameters.

Inspired on the Ruby on Rails gem Has Scope.

Install

Just include it in your composer.json file

Or add:

And run composer update.

Basic Usage

Imagine we have a Book model with two filters, by year and by author.

URL parameters might look like the following:

Steps

  1. Create your controller and be sure to inherit from Petrelli\ScopedController\BaseController.

  2. Define which class will hold your collection with the $entity variable. Usually an Eloquent Model, but could be any class that respond to scopes.

  3. Now define the $scopes variable as an Array following the pattern [ URLparameter => scopeName, .... ]

  4. Now to get a filtered collection simply call $this->collection(). You can use any available function. If using Eloquent, you could use get(), paginate(...), or anything you need to chain.

Customizing the scopes chain

We provide a controller function named beginOfAssociationChain() that you could overload. In there we build the base query over which we will apply all of our scopes.

For example:

Here every time we call $this->collection() as previously described we will be executing the published() scope, and also filtering books where 'library' is 'NYC'.

Applying scopes manually

We provide the function applyScopes($query) in case you want to manually apply your scopes to a query. As always, which scope will be triggered is a function of the request parameters.

Extra functionality

Scopes with multi-value parameters

If you need to define a multi-value parameter just pass it as an array and define the scopes as the following:

Defining the scope as an array will allow you to pass multiple parameters to it coming from the URL as arrays.

Multi-value scopes in action

You get the idea. The scope is nothing but a simple two parameter element.

Of course you can generalize to use any number of parameters. Simply add it to the $scopes definition.

Check if any filter is present

Common use case, if you need to check if any scope is present:

Use specific scopes for different actions

Because $this->collection() is returning a Query Builder (when using Eloquent for example), you could keep chaining methods and scopes as you would normally do:

License

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


All versions of scoped-controller with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0
laravel/framework Version ~5.6|~5.7|~5.8|^6.0|^7.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 petrelli/scoped-controller contains the following files

Loading the files please wait ....