Download the PHP package mjahn/eloquent-builder without Composer

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

Provides a Eloquent query builder for Laravel or Lumen

Build Status Coverage Status StyleCI Latest Stable Version Total Downloads License

This package allows you to build eloquent queries, based on request parameters. It greatly reduces the complexity of the queries and conditions, which will make your code cleaner.

Basic Usage

Suppose you want to get the list of the users with the requested parameters as follows:

In the legacy code the method written below was followed:

But after using the EloquentBuilder, the above code refactor as follows:

You just need to define filter for each parameter that you want to add to the query.

Tip: It's recommended validates the incoming requests before sending to filters.

Tip: It's recommended present filters inside a filter key in query string like this: user/search?filter[age_more_than]=25&filter[gender]=male
and then get them in this way: $request->only('filter').

Installation

Laravel

You can install the package via composer:

Laravel 5.5 uses Package Auto-Discovery, so you are not required to add ServiceProvider manually.

Laravel <= 5.4.x

If you don't use Auto-Discovery, add the ServiceProvider to the providers array in config/app.php file

And add the facade to your config/app.php file

Lumen

You can install the package via composer:

For Lumen, add the LumenServiceProvider to the bootstrap/app.php file

For using the facade you have to uncomment the line $app->withFacades(); in the bootstrap/app.php file

After uncommenting this line you have the EloquentBuilder facade enabled

Publish the configuration file

and add the configuration to the bootstrap/app.php file

Important : this needs to be before the registration of the service provider.

Default Filters Namespace

The default namespace for all filters is App\EloquentFilters with the base name of the Model. For example, the filters namespace will be App\EloquentFilters\User for the User model.

With Config file

You can optionally publish the config file with:

And set the namespace for your model filters which will reside in:

Define a Filter

Writing a filter is simple. Define a class that extends the Fouladgar\EloquentBuilder\Support\Foundation\Contracts\Filter abstract class. This class requires you to implement one method: apply. The apply method may add where constraints to the query as needed. Each filter class should be suffixed with the word Filter.

For example, take a look at the filter defined below:

Tip: Also, you can easily use local scopes in your filter. Because they are instance of the query builder.

Authorizing Filter

The filter class also contains an authorize method. Within this method, you may check if the authenticated user actually has the authority to apply a given filter. For example, you may determine if a user has a premium account, can apply the StatusFilter to get listing the online or offline people:

By default, you do not need to implement the authorize method and the filter applies to your query builder. If the authorize method returns false, a HTTP response with a 403 status code will automatically be returned.

Ignore Filters on null value

Filter parameters are ignored if contain empty or null values.

Suppose you have a request something like this:

Only the "published_post" filter will be applied on your query.

Work with existing queries

You may also want to work with existing queries. For example, consider the following code:

Use as Dependency Injection

Suppose you want use the EloquentBuilder as DependencyInjection in a Repository.

Let's have an example.We have a sample UserRepository as follows:

The filters method applies the requested filters to the query by using EloquentBuilder injected.

Injecting The Repository

Now,we can simply "type-hint" it in the constructor of our UserController:

Testing

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

Eloquent-Builder is released under the MIT License. See the bundled LICENSE file for details.

Built with :heart: for you.


All versions of eloquent-builder with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
illuminate/database Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0
illuminate/http Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0
illuminate/support Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.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 mjahn/eloquent-builder contains the following files

Loading the files please wait ....