In this tutorial you will learn about the Create Datatables in Laravel 8 Vue JS Application and its application with practical example.
In this Create Datatables in Laravel 8 Vue JS Application Tutorial I’ll show you how to create Datatables in laravel Vue Js application. In this tutorial you will learn to create datatables with Vue Js in laravel. In this article I will give you example on how to use Datatables with Vue Js with example in laravel 8.
Create Datatables in Laravel 8 Vue JS Application
In this step by step tutorial I will demonstrate you with example on how to create Datatables with Vue Js in laravel 8. Please follow the instruction given below:
- Create a laravel project
- Make database connection
- Generate and configure model, Run migration
- Create routes
- Generate and setting up the controller
- Setting up vue UI in laravel
- Configure a vue component
- Setting up views and vue components
- Run application
Install Laravel App
First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command
1 |
composer create-project laravel/laravel laravel-vue-datatables --prefer-dist |
Database Connection
Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.
1 2 3 4 5 6 |
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=db DB_USERNAME=root DB_PASSWORD= |
Model and Migration
Now, in this step we will create model and migration file. Please run the following command:
1 |
php artisan make:model Blog -m |
Put the following code in database/migrations/create_blogs_table.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateBlogsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('blogs', function (Blueprint $table) { $table->id(); $table->string('title'); $table->string('url'); $table->string('category'); $table->string('description'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('blogs'); } } |
Now add following code in app/Models/Blog.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Blog extends Model { use HasFactory; protected $fillable = [ 'title', 'url', 'category', 'description' ]; } |
Now, run the migration to create database table using following artisan command: