Download the PHP package tehekone/laravel-resources without Composer
On this page you can find all versions of the php package tehekone/laravel-resources. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-resources
Laravel Resource
Table of Contents
Click to expand
- [Introduction](#introduction) - [Installation](#installation) - [Usage](#usage) - [Defining Resource](#defining-resource) - [Defining Filters](#defining-filters) - [Cheat sheet](#cheat-sheet)
Introduction
Installation
You can install this package via composer using:
Alternatively, add these two lines to your composer require section:
Usage
...
Defining Resource
...
Defining Filters
- Select Filters
- Boolean Filters
- Date Filters
- Filter Titles
- Dynamic Filters
- Render Filters
Select Filters
Each select filter contains two methods: apply
and options
. The apply
method is responsible for modifying the query to achieve the desired filter state, while the options
method defines the "values" the filter may have. Let's take a look at an example UserType
filter:
The options
method should return an array of keys and values. The array's values will be passed into the apply
method as the $value
argument. This filter defines two possible values: admin
and editor
.
As you can see in the example above, you may leverage the incoming $value to modify your query. The apply method should return the modified query instance.
Boolean Filters
You may generate a boolean filter using the shine:filter --boolean
Artisan command.
Each boolean filter contains two methods: apply
and options
. The apply
method is responsible for modifying the query to achieve the desired filter state, while the options method defines the "values" the filter may have.
When building boolean filters, the $value
argument passed to the apply
method is an associative array containing the boolean value of each of your filter's options.
Let's take a look at an example UserType
filter:
The options
method should return an array of keys and values. The array's values will be passed into the apply
method as the $value
argument. This filter defines two possible values: admin
and editor
.
As you can see in the example above, you may leverage the incoming $value
to modify your query. The apply
method should return the modified query instance.
Date Filters
You may generate a date filter using the shine:filter --date
Artisan command.
Each date filter contains one method: apply
. The apply
method is responsible for modifying the query to achieve the desired filter state.
When building date filters, the $value
argument passed to the apply
method is the string representation of the selected date.
Let's take a look at an example CreatedFilter
filter:
As you can see in the example above, you may leverage the incoming $value
to modify your query. The apply
method should return the modified query instance.
Filter Titles
If you would like to change the filter title, you may define a name
property on the filter class:
If the name of your filter needs to be dynamic, you should create a name
method on the filter class:
Dynamic Filters
There may be times when you want to create a dynamic filter which filters on different columns. In addition to passing the column name that we want to filter on in the constructor, we'll also need to override the key
method.
Let's take a look at an example TimestampFilter
filter:
When registering the filter on a resource, pass the name of the column you wish to filter on:
Render Filters
By default all defined filter in resource renders by row. Let's take a look at an example:
But you also may want to take filter by key
and render it separately. From the example with the UserType
filter Let's take how it works by this example:
For get all user selected filters you may use selected
method and simple take count
. Let's take a look at an example:
Cheat sheet
Credits
Inspired by Laravel Nova
- TehekOne
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-resources with dependencies
ext-json Version *
illuminate/support Version 5.5.*||5.6.*||5.7.*||5.8.*
illuminate/console Version 5.5.*||5.6.*||5.7.*||5.8.*
illuminate/http Version 5.5.*||5.6.*||5.7.*||5.8.*
illuminate/view Version 5.5.*||5.6.*||5.7.*||5.8.*
illuminate/database Version 5.5.*||5.6.*||5.7.*||5.8.*