How To Install Yajra Datatable In Laravel 10

Websolutionstuff | Mar-01-2023 | Categories : Laravel

In this article, we will see how to install datatable in laravel 10. Here, we will learn about the laravel 10 yajra datatable example. As we all used datatable on our backend side project. So, here we will show you the laravel 10 datatable example.

Yajra datatable in laravel 10 is very easy to install and it is a famous package in laravel as well as in PHP. Yajra datatable is basically a jQuery plugin that allows you to add advanced interaction controls to your HTML tables data. Datatables also provide ajax for data searching and getting.

So, let's see yajra datatable in laravel 10, laravel 10 yajra datatable example, datatable example in laravel 10, and install yajra datatables laravel 10.

Step 1: Install Laravel 10 For Yajra Datatable Example

Step 2: Install Yajra Datatable Package

Step 3: Create Dummy Records Using Tinker

Step 4: Add New Route

Step 5: Create UserController For Datatable

Step 6: Create Blade File



Step 1: Install Laravel 10 For Yajra Datatable Example

Now, we will create a new project set up for this Laravel 10 Yajra Datatable Example.

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


Step 2: Install Yajra Datatable Package

In this step, we will run the following command in our project to get the latest version of the datatable package.

composer require yajra/laravel-datatables-oracle:"^10.0"

If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package.

composer require yajra/laravel-datatables:^9.0



This step is optional if you are using Laravel 5.5+.

After that, we need to add providers and alias in your project's config/app.php file

'providers' => [

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



Step 3: Create Dummy Records Using Tinker

After adding aliases and providers, we are adding some dummy records in database using the below command.

php artisan tinker

factory(App\User::class, 200)->create();


Step 4: Add New Route

Now, we will create a route for yajra datatable example in laravel 10


Route::get('users', ['uses'=>'App\Http\Controllers\UserController@index', 'as'=>'users.index']);


Step 5: Create UserController For Datatable

After adding the route we need to create a controller to manage the layout and get data requests and return responses.

php artisan make:controller UserController

Now, add the below code in the UserController.


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use DataTables;
class UserController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index(Request $request)
        if ($request->ajax()) {
            $data = User::latest()->get();
            return Datatables::of($data)
                    ->addColumn('action', function($row){
                           $btn = '<a href="javascript:void(0)" class="edit btn btn-primary btn-sm">View</a>';
                            return $btn;
        return view('users');



Step 6: Create Blade File

Now create a users.blade.php file. So. add the following code to that file.


<!DOCTYPE html>
    <title>How To Install Yajra Datatable In Laravel 10 - Websolutionstuff</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="" />
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <script src=""></script>  
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
<div class="container">
    <h1>How To Install Yajra Datatable In Laravel 10</h1>
    <table class="table table-bordered data-table">
                <th width="100px">Action</th>
<script type="text/javascript">
  $(function () {
    var table = $('.data-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('users.index') }}",
        columns: [
            {data: 'DT_RowIndex', name: 'DT_RowIndex'},
            {data: 'name', name: 'name'},
            {data: 'email', name: 'email'},
            {data: 'action', name: 'action', orderable: false, searchable: false},


You might also like:

Recommended Post
Featured Post
Laravel whereMonth and whereYear Example
Laravel whereMonth and whereYe...

In this article, we will show you laravel whereMonth and whereYear examples. whereMonth and whereYear are...

Read More


Character Count In Textarea
Character Count In Textarea

In this article, we will explain to you how to count characters from textarea. many times a client has requirements...

Read More


Autocomplete Search from Database in Laravel 11
Autocomplete Search from Datab...

Hello, laravel web developers! In this article, we'll see how to autocomplete a search from a database in larav...

Read More


REST API In Laravel
REST API In Laravel

In this article, we will explore the world of RESTful APIs in the context of Laravel, encompassing versions 8, 9, and 10...

Read More