Download the PHP package ymigval/laravel-model-datatable-ssp without Composer
On this page you can find all versions of the php package ymigval/laravel-model-datatable-ssp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ymigval/laravel-model-datatable-ssp
More information about ymigval/laravel-model-datatable-ssp
Files in ymigval/laravel-model-datatable-ssp
Package laravel-model-datatable-ssp
Short Description Extension designed to seamlessly integrate Laravel models with server-side DataTables. It provides a convenient and efficient way to fetch, transform, and display data from your Laravel models in DataTables.
License MIT
Informations about the package laravel-model-datatable-ssp
Processing Laravel Models with DataTables
Extension designed to seamlessly integrate Laravel models with server-side DataTables. It provides a convenient and efficient way to fetch, transform, and display data from your Laravel models in DataTables.
Installation
To get started, install the package via Composer:
Usage with Eloquent Models
To use DataTables with an Eloquent model, you can create an instance or query your model and call the datatable()
method with column mappings.
Alternatively, you can call the static datatable()
method:
- Replace
Customer
with your Eloquent model. ['first_name' => 'first_name', 'last_name' => 'last_name', 'phone' => 'phone']
: Define the mappings of your model's fields.
Customizing Columns
You can customize field values by providing closures in your column mappings.
- $field: Contains the value of the field in that mapping.
- $row: Contains the values of the fields in the context of the current row.
Adding Additional Columns
You can add additional columns by using closures:
Fields in Context
Define model fields in context to access related data or perform custom formatting.
By default, fields added to the context cannot be searched and sorted. You can configure this behavior by adding options to the field:
Usage with Query Builder
You can use DataTable with Query Builder by calling dataTable()
on a query builder instance.
Transforming Output Data
You can transform the datatable return into various formats such as response
, array
, or json
by specifying it as the third parameter.
By default, a response is returned.
Advanced Usage
Using Callbacks for Column Mappings
You can use a callback to define columns dynamically.
Union Queries
Perform union queries with DataTable.
You can also add aliases to the fields in the column mapping or fields in context:
Using Eloquent Relationships
Note on Using Relations
When using relations, there are some limitations:
- Avoid using related fields as column values without a closure.
- To utilize the value of a related field, it should be accessed through a formatting closure. Use the second parameter of the closure to access the value. Remember that the second parameter contains the values of the fields in the context of the current row.
- Related fields cannot be sorted or searched.
Please make sure to add the local key used in the relation to your column mappings or fields in context.
For more usage examples, refer to the test cases.
Installing DataTables in Your Application
In the official DataTables documentation: https://datatables.net/, you will find the steps to install the library in your application.
Check out the server-side processing examples: https://datatables.net/examples/server_side/simple.html
Changelog
Please refer to the CHANGELOG for more information about recent changes.
License
The MIT License (MIT). For more information, please see the License File.