Download the PHP package bogdanpet/eloquent-datatable without Composer
On this page you can find all versions of the php package bogdanpet/eloquent-datatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-datatable
Description
PHP class for displaying Eloquent collections as HTML table. Tested in Laravel, but should work in any project using eloquent as standalone package.
Installation
Download and require Datatable.php and DatatableActions.php. or install it via composer.
Usage
Basic usage
For example, let's say that we have collection of users we want to show as a table. Creating collection and sharing it to your view should look like this in Laravel.
Now, if you are intending to show this collection as HTML table you can do this simply with Datatable class. You can either create new instance or take advantage of laravel's dependency injection.
Then, in your blade template, just put table where you want it using show() method.
If you need to customize table more, you can use separate methods instead of show() method.
Static usage
For quick building of datatable in your view, if you already have access to collection, you can create table directly with static method make().
Datatable actions
For generating action links I provided custom column 'actions'. For example, if you want to create links to edit and delete user from database, you can add 'actions' to columns and then set actions.
As you can see, actions are set as array of arrays, each array contains link text as first item, route as second and optional third item which is array of link attributes. {id} is wildcard for laravel routing system, and will be replaced with corresponding user's id from the database. You can use wildcard for any database column like {name} or {email}. Example above will generate two links for each user in actions column.
Advanced usage
For complete control over your datatable you can extend main Datatable class. For example, Let's create UsersDatatable class.
After class is created, it can be used same as main class. Just no need for defining columns and actions. Main data can also be defined, but it is not recommended because of its dynamic behavior.
And, same as in first example, just place the datatable where you want to.
'row_num', like 'actions', is predefined custom column which generate number of row in a table. You can also add your own custom columns or customize existing ones using 'th' and 'td' methods. Let's add new custom column 'registered_at' and customize 'name' column in our UsersDatatable class above.