Laravel Datatables | Yajra Datatables For Laravel 7

Hello Artisan 

In this tutorial, I am going to share with you how to install and use datatables in laravel 7 application. In this laravel demo datatable tutorial, i will use datatables laravel datatables plugin. I will write step by step tutorial for laravel datatables ajax.

Datatables provide you with quick search, ordering, sorting, pagination, etc. Datatables is a jQuery plugin that allows us to add some advanced interaction controls to your HTML tables data.

Datatables also provide ajax for data searching and getting. you can give a very quick layout for search and sorting using Datatables. We can also implement Datatables in your laravel 7 application.


Step 1: Install Laravel 7

In this step, we have to download a fresh laravel app to create step by step laravel yajra datatable example. So download it by the following command.

composer create-project --prefer-dist laravel/laravel datatable


Step 2 : Install Yajra Datatable Package

Now we have to install yajra datatable package in our laravel app. So run the below command to install it.

composer require yajra/laravel-datatables-oracle


After that, you need to add providers and alias in the following path.


'providers' => [
'aliases' => [
	'DataTables' => Yajra\DataTables\Facades\DataTables::class,


Step 3:  Add Dummy Records

In this, we need to add some dummy records to show datatable. I will create a user list to show it in datatable. I will use tinker to add it quickly. 

php artisan tinker
factory(App\User::class, 100)->create();


Step 4:  Create Route

In this step, we have to set up our route. I won't use any controller to create and show our users. I will simply return the user from the route for demo purposes. So follow the below guide to create laravel datatable.


//Datatable Route
Route::get('users', function(){
  return view('test');

Route::get('userslist', function(){
  return datatables()->of(\DB::table('users')->select('*'))


Step 5: Create Blade To View Datatable

Now in this final step, we need to create a blade to view datatable. So create test.blade.php and add the following code it.



Read also : Dynamic Pie Charts Example Using Google Charts API in Laravel 7


Now run php artisan serve command and visit this below path then you will see the below datatable.




And see the preview of this laravel yajra datatable tutorial's output.




Read also: Filter Data Between Two Dates in Yajra Datatables in Laravel


Hope it can help you.