yajra-datatables-in-Laravel-10

Implementing Yajra DataTables in Laravel 10: A Step-by-Step Guide

Share this post on:

Welcome to our step-by-step guide on implementing Yajra DataTables in a Laravel 10 project. Yajra DataTables is a powerful library that seamlessly integrates the jQuery DataTables API with Laravel. It simplifies server-side operations using AJAX and supports Eloquent ORM, Fluent Query Builder, or Collection.

Follow along as we set up a Laravel project, install Yajra Datatables, create a model and migrations, generate dummy records, set up a controller, define routes, and finally, display records with a visually stunning table using Bootstrap.

Step 1: Install the Laravel App

Let’s start by creating a new Laravel project using Composer:

Step 2: Install Yajra Datatable Package

Next, we’ll install the Yajra DataTable plugin:

After installing, expand the foundational service by adding the service provider and alias in the config/app.php file:

Run the vendor publish command:

Step 3: Set Up the Model and Migrations

Generate a model and migration for the ‘blogs’ table:

Add the following code to the generated migration file:

In the app/Models/Blog.php file, add the following code:

Run the migration command:

Step 4: Generate Dummy Records

To test Yajra Datatables, let’s create dummy records using Faker. Open database/seeders/DatabaseSeeder.php and add the following code:

Run the seeder command:

Step 5: Create a Controller

Now, let’s create a controller for our Blog model:

Open the file app/Http/Controllers/BlogController.php and add the following code:

Step 6: Create Routes

Create routes to display the data table in our view. Open routes/web.php and add the following code:

Step 7: Displaying Records with Laravel Yajra Datatables

Create the welcome.blade.php  file in resources/views/ and place the following code:

Finally, run the following command and view the result in your browser:

Visit http://<hostname>:<port>/ to see the Yajra Datatables in action!

Author: Piyush Solanki

Piyush is a seasoned PHP Tech Lead with 10+ years of experience architecting and delivering scalable web and mobile backend solutions for global brands and fast-growing SMEs. He specializes in PHP, MySQL, CodeIgniter, WordPress, and custom API development, helping businesses modernize legacy systems and launch secure, high-performance digital products.

He collaborates closely with mobile teams building Android & iOS apps , developing RESTful APIs, cloud integrations, and secure payment systems using platforms like Stripe, AWS S3, and OTP/SMS gateways. His work extends across CMS customization, microservices-ready backend architectures, and smooth product deployments across Linux and cloud-based environments.

Piyush also has a strong understanding of modern front-end technologies such as React and TypeScript, enabling him to contribute to full-stack development workflows and advanced admin panels. With a successful delivery track record in the UK market and experience building digital products for sectors like finance, hospitality, retail, consulting, and food services, Piyush is passionate about helping SMEs scale technology teams, improve operational efficiency, and accelerate innovation through backend excellence and digital tools.

View all posts by Piyush Solanki >