Requirements
Installation
Run the below-mentioned artisan command to install a new laravel application.
Then install the Yajra DataTable plugin in Laravel.
Setup
Go to config/app.php
file and paste this inside.
Run vendor publish command.
Create Model
Run command to create a model
Open database/migrations/migrationtimestamp_create_students_table.php
file and paste
Open app/Models/Student.php
and paste in the $fillable
array.
Run migration
Insert Dummy Data/ Records
Open the database/seeds/DatabaseSeeder.php
file and add the following code
Run the following command to generate dummy data
Now you will have data that looks something like this!
Create Controller
Create a controller using the below command
Open app/Http/Controllers/StudentController.php
file and add the following code
Define Route
Open routes/web.php
and add the given code
Create the View and Display Data inside the DataTable
Open resources/views/welcome.blade.php
file and place the following code.
The DataTable()
method is defined, and the AJAX request
is fetching the data from the server and displaying the name
, email
, user name
, phone number
and date of birth
with the help of Yajra DataTable package.
We have also set orderable
and searchable
properties to true, so that you can search the data smoothly and make your programming tasks prosperous.
Now lets check it!
Run the following command and check our progress on the browser.
This is what it should look like!
Reference: Laravel 8 - DataTables Server Side Rendering (5 easy steps)