Download the PHP package laralabs/datatablejson without Composer
On this page you can find all versions of the php package laralabs/datatablejson. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laralabs/datatablejson
More information about laralabs/datatablejson
Files in laralabs/datatablejson
Package datatablejson
Short Description Easily generate DataTable JSON from an eloquent collection and bind it to the view
License MIT License
Informations about the package datatablejson
DataTableJson for Laravel
This package aims to simplify the process of creating JSON data for DataTable components.
Recently I started using a Vue DataTable component and found that I needed a simple way of formatting and passing the data into the view to keep everything tidy.
Installation
Install the package via composer
Once you have updated composer, add the Service Provider to your providers
array within config/app.php
Now you can publish the config file to config/datatablejson.php
Edit the published configuration file to suit your application.
It is recommended that you change the namespace from the default 'window'
Usage
Add the trait to the top of your Eloquent Model
Add public $columns = []
to your model, this defines the columns that will be used in the table.
Here is an example of a populated $columns
array:
The Actions
column in the example shows how you create columns that can include HTML snippets, pull in data from other fields by using {field_name}
Once the columns have been defined you can then create a collection and apply the conversion function.
This will build up the data and prepend it to the view that you specified in the configuration file.
Got a special case and need a different set of fields?
You can pass a $columns
array to this function which will override the columns specified in the model.
This package is designed to work well with MicroDroid/vue-materialize-datatable
Credits
Thanks to Jeffrey Way over at Laracasts for his awesome Laracasts/PHP-Vars-To-Js-Transformer package which allowed me to include the view binding functionality.
Support
Please raise an issue on Github if there is a problem.
License
This is open-sourced software licensed under the MIT license.
All versions of datatablejson with dependencies
illuminate/support Version 5.4.*|5.5.*
illuminate/database Version 5.4.*|5.5.*
illuminate/contracts Version 5.4.*|5.5.*