Laravel 7 Vue JS Post Axios Request Example

In this tutorial you will learn about the Laravel 7 Vue JS Post Axios Request Example and its application with practical example.

In this Laravel 7 Vue JS Axios post Request Example tutorial, I’ll show you how to implement post request with Vue JS Axios in laravel. In this tutorial you will learn to create post request with Vue JS Axios in laravel.

Laravel 7 Vue JS Post Axios Request Example

  • Step 1: Download Laravel Fresh Setup
  • Step 2: Setup Database Credentials
  • Step 3: Make Migration & Model
  • Step 4: Add Routes
  • Step 5: Make Controller By Command
  • Step 6: Install Vue Js dependency
  • Step 7: Create blade file and layout
  • Step 8: Run Development Server

Step 1: Download Laravel Fresh Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 2: Setup Database Credentials

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.

Step 3: Make Migration & Model

Now, in this step we will create model and migration file for form. Please run the following command:

after that, open your posts migration file and paste the following code:


Again open your terminal and run the php artisan migrate to migrate our tables into your database:

After that, open Post model and update the following code into your app/Post.php model file:

Step 4: Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 5:  Make Controller By Command

Now, lets create a controller named PostController using command given below –

This command will create a controller that name PostController inside the controller folder. Next, open it app/Https/Controller/PostController.php and update the following methods into your PostController file:

Step 6: Install Vue Js dependency

now open webpack.mix.js file and update the following code into your file. Make an asstes folder inside resources folder and copy js and sass folder inside it. Thats all. We need it to setup our laravel mix

Next Go to resources/assets/js/components/ folder. And create a new components name PostComponent.vue. Then update the following code into your PostComponent.vue file:

The above code is to send form data to controller using axios post request in laravel. Next, Go to resources/assets/js then open app.js file and intialize vue js components in this file. So open app.js file and update the following code into your app.js file:

Step 7: Create blade file and layout

Now, Open resources/layouts/app.blade.php and update the following code into it:

Next, resources/views/ and create a new blade view file name post.blade.php. And update the following code into your post.blade.php view file:

Step 8: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 7 Vue JS Post Axios Request Example and its application with practical example. I hope you will like this tutorial.