Mateus Gonçalves
Mateus Gonçalves

Reputation: 706

DataTables with Laravel

has instead how to use the index method to render, use another one? For DataTables requires the index and the method that calls the DataTables, however, I'm already using the index and I need to open my table somewhere else

Upvotes: 1

Views: 2006

Answers (2)

Bhoomi Patel
Bhoomi Patel

Reputation: 775

you have to use package for DataTables. the package name for laravel datatables is yajra.

refers this link for datatables: https://datatables.yajrabox.com/

Upvotes: 1

Ismoil  Shifoev
Ismoil Shifoev

Reputation: 6001

Laratables is a package by Gaurav Makhecha to handle server-side AJAX of DataTables (Table plug-in for jQuery) in Laravel +5.5:

This package helps with simple requirements of displaying data from eloquent models into data tables with ajax support. Plus, using simple relationships and customizing column values.

With this package the client-side code looks similar to any other usage of the Datatables plugin for jQuery:

$('#users-table').DataTable({
    serverSide: true,
    ajax: "{{ route('admin.users.datatables') }}",
    columns: [
        { name: 'id' },
        { name: 'name' },
        { name: 'email' },
        { name: 'role.name' },
        { name: 'action', orderable: false, searchable: false }
    ],
    ...
});

Note role.name in the columns property, which is a relationship column on the User model with the name of the relationship and the field.

On the server-side, here’s what a data tables controller might look like to provide the data:

use App\User;
use Freshbitsweb\Laratables\Laratables;
...
return Laratables::recordsOf(User::class);

You can findinstallation instructions from the GitHub – freshbitsweb/laratables repository.

I used on my own project it working. I think it will be helpful

Upvotes: 1

Related Questions