Laravel 11 Yajra Datatables Example Tutorial

Laravel 11 Yajra Datatables Example Tutorial

To install and use yajra DataTables in laravel 11; Run composer require yajra/laravel-datatables-oracle command to install yajra dataTables and use function datatables()->of($data)->make(true) of dataTable with data and pass it on views to display in table in laravel application.

In this example guide, we will create a table and display data with searching, sorting, pagination using yajra dataTables package in laravel 11 applications.

Steps for How to Install and Use Yajra Datatables in Laravel 11

Here are steps:

Step 1: Download the New Laravel Application

Run composer create-project --prefer-dist laravel/laravel LaravelDataTables command on cmd to download and setup new laravel application into your system:

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

Step 2: Configure the Database with the Application

Open .env file from root folder of laravel project, and configure database details into it; something like this:


Step 3: Install Yajra DataTables Package

Run the composer require yajra/laravel-datatables-oracle command on cmd to install yajra dataTables in laravel project:

cd LaravelDataTables
composer require yajra/laravel-datatables-oracle

In laravel 11 version, you do not need to add dataTables aliases and providers in app.php file.

Step 4: Add Dummy Data on Database

Run the following command on cmd to generate fake data for testing Yajra dataTables in the laravel project; something like this:

php artisan tinker

Step 5: Create Controller File

Run php artisan make:controller MyTestController command on cmd to create a new controller file:

php artisan make:controller MyTestController

Now open MyTestController.php file from app/http/controllers folder, and create one method to pass data on dataTable views; something like this:

namespace App\Http\Controllers;
use Illuminate\Http\Request;

use App\Models\User;

use DataTables;
class MyTestController extends Controller
     //handle yajra datatable views and data
    public function dataTableLogic(Request $request)
        if ($request->ajax()) {
            $users = User::select('*');
            return datatables()->of($users)
        return view('y-dataTables');

Step 6: Define Routes

Open web.php file from routes folder, and create route in it to handle logic between controller and view file; something like this:

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\MyTestController;
Route::get('list', [MyTestController::class, 'dataTableLogic']);

Step 7: Create View

To create view file name y-dataTables.blade.php in resources/views folder to show dataTables with data from database; something like this:

<!DOCTYPE html>

<html lang="en">
<title>Laravel 11 DataTables Example -</title>

 <link href="[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<script src="[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>

<script src=""></script>

<link  href="" rel="stylesheet">

<script src=""></script>

         <div class="container">
               <h2>Laravel 11 DataTables Example -</h2>
            <table class="table table-bordered" id="y_dataTables">
                     <th>Created at</th>
   $(document).ready( function () {
           processing: true,
           serverSide: true,
           ajax: "{{ url('list') }}",
           columns: [
                    { data: 'id', name: 'id' },
                    { data: 'name', name: 'name' },
                    { data: 'email', name: 'email' },
                    { data: 'created_at', name: 'created_at' }

Step 8: Run and Test Application

Run php artisan serve command on cmd to start application server:

php artisan serve

Ready to run this app at URL on browser:


We hope with the help of this example tutorial guide you have learned how to install and use YAJRA DataTables in laravel 11 applications.

Here are some new guides related to Laravel 11; You must check them out:


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *