Friday, June 21, 2024

Datatables with dynamic data in laravel

Datatables with dynamic data in laravel

Hello to all, welcome to In this post, I will tell you, Datatables with dynamic data in laravel. Laravel is one of the top php mvc framework


Datatables are the powerful jquery plug-in and it is used to create table listing with sorting and searching and many more functionality.

Today, we will use data-tables in laravel with dynamic content.

Here is the working and tested code and you can easily apply into your laravel project.

I am doing select query with pdo and for pdo connectivity in laravel you can check this link:

First, we will do code in laravel controller:

public function index()
        $SQL_clientdetails = $this->PDO->prepare("SELECT * FROM `user` ORDER BY id ASC");
        $clientdetails = $SQL_clientdetails->fetchAll(\PDO::FETCH_OBJ);
        return view('index', compact('clientdetails'));

 Now, Here is below code for laravel view:

<table id="clientsTable" class="table display responsive nowrap">
          <th>Mobile Number</th>
          <th>Date of Birth</th>
        @foreach($clientdetails as $key => $client)
          <tr id="{!! $client->id; !!}">
            <td>{{ $client->id }}</td>
            <td>{{ $client->name }}</td>
            <td>{{ $client->phone }}</td>
            <td>{{ $client->email }}</td>
            <td>{{ $client->dob }}</td>
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
    $(document).ready(function() {
    var cTable = $('#clientsTable').DataTable({
    "columns": [
      { "searchable": false, "visible": true, },
      { "searchable": true, "visible": true, },
      { "searchable": true, "visible": true, },
      { "searchable": false, "visible": true, },
      { "searchable": false, "visible": false, },
    bLengthChange: false,
    searching: true,
    responsive: true,
    "autoWidth": false,
    language: {
      searchPlaceholder: 'Search by name or mobile no ...',
      sSearch: '',

 There are so many code tricks in laravel and i will let you know all. Please do comment if you any query related to this post. Thank you.


the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.