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!

Piyush Solanki

PHP Tech Lead & Backend Architect

10+ years experience
UK market specialist
Global brands & SMEs
Full-stack expertise

Core Technologies

PHP 95%
MySQL 90%
WordPress 92%
AWS 88%
  • Backend: PHP, MySQL, CodeIgniter, Laravel
  • CMS: WordPress customization & plugin development
  • APIs: RESTful design, microservices architecture
  • Frontend: React, TypeScript, modern admin panels
  • Cloud: AWS S3, Linux deployments
  • Integrations: Stripe, SMS/OTP gateways
  • Finance: Secure payment systems & compliance
  • Hospitality: Booking & reservation systems
  • Retail: E-commerce platforms & inventory
  • Consulting: Custom business solutions
  • Food Services: Delivery & ordering systems
  • Modernizing legacy systems for scalability
  • Building secure, high-performance products
  • Mobile-first API development
  • Agile collaboration with cross-functional teams
  • Focus on operational efficiency & innovation

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. With extensive experience in the UK market and across multiple sectors, Piyush is passionate about helping SMEs scale technology teams and accelerate innovation through backend excellence.