Kritim Yantra
May 16, 2025
Are you a beginner trying to combine Laravel, Vue.js, and Bootstrap in a single project? 🤔
You're in the right place! In this guide, we’ll build a small web application using:
By the end of this tutorial, you'll have a neat and simple app with two pages — Home and About — and the knowledge to build more!
Make sure you have the following installed:
Let’s get started by creating a new Laravel app.
Open your terminal and run:
composer global require laravel/installer
laravel new laravel-vue-bootstrap
cd laravel-vue-bootstrap
Check the Laravel version:
php artisan --version
# You should see something like Laravel Framework 12.x.x
To make our app look nice and responsive, let’s install Bootstrap 5.
Run this command to install Bootstrap and Popper:
npm install bootstrap@5 @popperjs/core
Now, open resources/js/app.js
and add:
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap';
This will include Bootstrap’s CSS and JavaScript.
Let’s compile our assets:
npm install
npm run dev
💡 Tip: You can test it by adding a Bootstrap button inside resources/views/welcome.blade.php
.
<button class="btn btn-primary">Hello Bootstrap!</button>
Laravel 12 uses Vite by default to handle assets, which is perfect for Vue.js.
npm install vue@3 @vitejs/plugin-vue
vite.config.js
:Replace the content with this:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
vue(),
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
resolve: {
alias: {
vue: 'vue/dist/vue.esm-bundler.js',
},
},
});
resources/js/app.js
to use Vue:import './bootstrap';
import { createApp } from 'vue';
import router from './router'; // We’ll create this next!
const app = createApp({});
app.use(router);
app.mount('#app');
Let’s add routing to our Vue app so we can navigate between pages.
npm install vue-router@4
resources/js/router.js
import { createRouter, createWebHistory } from 'vue-router';
const routes = [
{
path: '/',
name: 'home',
component: () => import('./components/Home.vue'),
},
{
path: '/about',
name: 'about',
component: () => import('./components/About.vue'),
},
{
path: '/:pathMatch(.*)*',
redirect: '/',
},
];
export default createRouter({
history: createWebHistory(),
routes,
});
We’ll now create two simple pages: Home and About.
Create a file: resources/js/components/Home.vue
<template>
<div class="container mt-5">
<h1 class="text-primary">🏠 Home Page</h1>
<p>Welcome to our Laravel + Vue 3 project!</p>
<router-link to="/about" class="btn btn-outline-primary">Go to About</router-link>
</div>
</template>
<script setup></script>
Create a file: resources/js/components/About.vue
<template>
<div class="container mt-5">
<h1 class="text-success">ℹ️ About Page</h1>
<p>This is a demo using Vue Router inside Laravel.</p>
<router-link to="/" class="btn btn-outline-success">Back to Home</router-link>
</div>
</template>
<script setup></script>
Now we need to render our Vue app inside a Laravel Blade file.
Open resources/views/welcome.blade.php
and replace everything with:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Laravel + Vue App</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
<div id="app"></div>
</body>
</html>
This will mount your Vue app into the <div id="app"></div>
.
In your terminal, run:
php artisan serve
npm run dev
Now open your browser and go to:
http://localhost:8000
🎉 You should see your Home page with a button to go to the About page!
You’ve successfully created:
Here are some ideas to take this further:
Learning how Laravel and Vue.js work together gives you the power to build modern web apps easily. You’ve just taken your first step into full-stack development. Keep practicing and building more apps.
If you found this tutorial helpful, don’t forget to share it with your developer friends! 😊
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google