Top Related Projects
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
The power of webpack, distilled for the rest of us.
Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
The Intuitive Vue Framework.
Quasar Framework - Build high-performance VueJS user interfaces in record time
Quick Overview
Laravel-Vue-SPA is a full-stack web application boilerplate that combines Laravel, Vue.js, and Tailwind CSS. It provides a solid foundation for building single-page applications (SPAs) with a robust backend API and a modern frontend framework, offering features like authentication, internationalization, and a pre-configured development environment.
Pros
- Seamless integration of Laravel (backend) and Vue.js (frontend) for full-stack development
- Includes pre-configured authentication system with JWT tokens
- Supports internationalization out of the box
- Utilizes Tailwind CSS for rapid UI development
Cons
- May have a steeper learning curve for developers not familiar with both Laravel and Vue.js
- Opinionated structure might not fit all project requirements
- Regular maintenance required to keep dependencies up-to-date
- Limited customization options without modifying the core structure
Code Examples
- API Route Definition (Laravel):
Route::group(['middleware' => 'auth:api'], function () {
Route::post('logout', [LoginController::class, 'logout']);
Route::get('user', [UserController::class, 'current']);
});
This code defines protected API routes using Laravel's route group with authentication middleware.
- Vue Component Example:
<template>
<div class="flex items-center justify-between">
<h1 class="text-2xl font-semibold">{{ $t('home') }}</h1>
<LocaleDropdown />
</div>
</template>
<script>
import LocaleDropdown from '~/components/LocaleDropdown'
export default {
components: {
LocaleDropdown
}
}
</script>
This Vue component demonstrates the use of internationalization and component composition.
- Vuex Store Action:
export const actions = {
async fetchUser ({ commit }) {
try {
const { data } = await axios.get('/api/user')
commit('SET_USER', data)
} catch (e) {
commit('SET_USER', null)
}
}
}
This Vuex action fetches the current user data from the API and updates the store.
Getting Started
-
Clone the repository:
git clone https://github.com/cretueusebiu/laravel-vue-spa.git
-
Install PHP dependencies:
composer install
-
Install and compile frontend dependencies:
npm install npm run dev
-
Configure your environment:
cp .env.example .env php artisan key:generate
-
Run migrations and start the development server:
php artisan migrate php artisan serve
Visit http://localhost:8000
in your browser to see the application running.
Competitor Comparisons
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Pros of Vue
- Core Vue framework with extensive ecosystem and community support
- Highly flexible and can be integrated into various project types
- Comprehensive documentation and learning resources
Cons of Vue
- Requires additional setup for full-stack applications
- Less opinionated about project structure and backend integration
- May need more configuration for features like authentication and API handling
Code Comparison
Laravel-Vue-SPA:
// routes/api.php
Route::group(['middleware' => 'auth:api'], function () {
Route::post('logout', 'Auth\LoginController@logout');
Route::get('/user', 'Auth\UserController@current');
});
Vue:
// main.js
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
Summary
Vue is a versatile frontend framework that offers flexibility and a rich ecosystem. Laravel-Vue-SPA, on the other hand, provides a pre-configured full-stack solution combining Laravel and Vue.js. While Vue allows for more customization, Laravel-Vue-SPA offers out-of-the-box features like authentication and API integration, making it easier to start building full-stack applications quickly. The choice between the two depends on project requirements and developer preferences for structure and setup.
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
Pros of Laravel
- Provides a clean, standard Laravel installation without additional complexities
- Offers more flexibility for developers to choose their own frontend stack
- Maintains a smaller footprint, making it easier to customize from scratch
Cons of Laravel
- Lacks built-in Vue.js integration and SPA setup
- Requires more initial setup for creating a full-stack application
- Does not include pre-configured authentication and user management features
Code Comparison
Laravel (routes/web.php):
Route::get('/', function () {
return view('welcome');
});
Laravel Vue SPA (routes/api.php):
Route::group(['middleware' => 'auth:api'], function () {
Route::post('logout', 'Auth\LoginController@logout');
Route::get('/user', 'Auth\UserController@current');
});
The Laravel Vue SPA repository provides a more comprehensive starting point for building a Single Page Application with Vue.js and Laravel, including API routes and authentication setup. In contrast, the standard Laravel repository offers a minimal setup, allowing developers to build their application structure from the ground up.
The power of webpack, distilled for the rest of us.
Pros of Laravel Mix
- Simpler setup and configuration for asset compilation
- Broader scope, handling various asset types beyond just JavaScript and Vue
- More actively maintained with frequent updates and improvements
Cons of Laravel Mix
- Less opinionated structure for Vue.js integration
- Requires additional configuration for advanced SPA features
- May need extra packages for full-fledged SPA functionality
Code Comparison
Laravel Mix configuration:
mix.js('resources/js/app.js', 'public/js')
.vue()
.sass('resources/sass/app.scss', 'public/css');
Laravel Vue SPA webpack configuration:
module.exports = {
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'@': path.join(__dirname, './resources/js')
}
},
// ... more configuration
}
Laravel Mix focuses on simplifying asset compilation with a fluent API, while Laravel Vue SPA provides a more structured approach for building Single Page Applications with Vue.js in Laravel. Laravel Mix offers flexibility for various project types, whereas Laravel Vue SPA is tailored specifically for Vue.js SPAs with Laravel, including pre-configured routing and authentication features.
Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
Pros of Inertia
- Seamless integration between backend and frontend, allowing for a more traditional server-side rendering approach
- Supports multiple frontend frameworks (Vue, React, Svelte) out of the box
- Simplifies data passing between server and client, reducing API complexity
Cons of Inertia
- Less flexibility in separating frontend and backend, which may limit scalability for larger applications
- Steeper learning curve for developers accustomed to traditional SPA architectures
- May require more server resources due to server-side rendering
Code Comparison
Laravel-Vue-SPA:
import Vue from 'vue'
import router from './router'
import store from './store'
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
Inertia:
import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
createInertiaApp({
resolve: name => require(`./Pages/${name}`),
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
.mount(el)
},
})
The Laravel-Vue-SPA example shows a traditional Vue.js setup with router and store, while the Inertia example demonstrates its integration with Vue 3 and server-side routing.
The Intuitive Vue Framework.
Pros of Nuxt
- Built-in server-side rendering (SSR) capabilities, improving SEO and initial page load times
- Automatic code splitting and optimized performance out of the box
- Rich ecosystem with a wide range of modules and plugins
Cons of Nuxt
- Steeper learning curve for developers new to the Nuxt ecosystem
- Less flexibility in backend technology choices compared to Laravel-Vue-SPA
Code Comparison
Laravel-Vue-SPA:
Route::get('/{any}', 'SpaController@index')->where('any', '.*');
Nuxt:
export default {
target: 'static',
// or
target: 'server'
}
The Laravel-Vue-SPA example shows a catch-all route for the SPA, while the Nuxt example demonstrates the ease of configuring static or server-side rendering.
Key Differences
- Laravel-Vue-SPA combines Laravel (PHP) backend with Vue.js frontend, while Nuxt is a Vue.js-based framework
- Nuxt provides a more opinionated structure and built-in features for Vue.js applications
- Laravel-Vue-SPA offers more backend flexibility, allowing developers to leverage Laravel's robust ecosystem
Use Cases
- Choose Laravel-Vue-SPA for projects requiring a powerful PHP backend with Vue.js frontend
- Opt for Nuxt when building Vue.js applications with SSR requirements or when seeking a more structured Vue.js development experience
Quasar Framework - Build high-performance VueJS user interfaces in record time
Pros of Quasar
- Comprehensive UI component library with Material Design support
- Cross-platform development capabilities (web, mobile, desktop)
- Active community and regular updates
Cons of Quasar
- Steeper learning curve due to its extensive feature set
- Less integration with Laravel backend compared to Laravel Vue SPA
Code Comparison
Laravel Vue SPA:
import Vue from 'vue'
import VueRouter from 'vue-router'
import { routes } from './routes'
Vue.use(VueRouter)
export default new VueRouter({
routes,
mode: 'history'
})
Quasar:
import { route } from 'quasar/wrappers'
import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router'
import routes from './routes'
export default route(function (/* { store, ssrContext } */) {
const createHistory = process.env.SERVER
? createMemoryHistory
: (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory)
const Router = createRouter({
scrollBehavior: () => ({ left: 0, top: 0 }),
routes,
history: createHistory(process.env.VUE_ROUTER_BASE)
})
return Router
})
The code comparison shows that Quasar provides more advanced routing options and configuration, while Laravel Vue SPA offers a simpler setup. Quasar's approach allows for greater flexibility in handling different environments and routing modes.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Laravel-Vue SPA
A Laravel-Vue SPA starter kit.
Features
- Laravel 8
- Vue + VueRouter + Vuex + VueI18n + ESlint
- Pages with dynamic import and custom layouts
- Login, register, email verification and password reset
- Authentication with JWT
- Socialite integration
- Bootstrap 5 + Font Awesome 5
Installation
composer create-project --prefer-dist cretueusebiu/laravel-vue-spa
- Edit
.env
and set your database connection details - (When installed via git clone or download, run
php artisan key:generate
andphp artisan jwt:secret
) php artisan migrate
npm install
Usage
Development
npm run dev
Production
npm run build
Socialite
This project comes with GitHub as an example for Laravel Socialite.
To enable the provider create a new GitHub application and use https://example.com/api/oauth/github/callback
as the Authorization callback URL.
Edit .env
and set GITHUB_CLIENT_ID
and GITHUB_CLIENT_SECRET
with the keys form your GitHub application.
For other providers you may need to set the appropriate keys in config/services.php
and redirect url in OAuthController.php
.
Email Verification
To enable email verification make sure that your App\User
model implements the Illuminate\Contracts\Auth\MustVerifyEmail
contract.
Testing
# Run unit and feature tests
vendor/bin/phpunit
# Run Dusk browser tests
php artisan dusk
Changelog
Please see CHANGELOG for more information what has changed recently.
Top Related Projects
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
The power of webpack, distilled for the rest of us.
Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
The Intuitive Vue Framework.
Quasar Framework - Build high-performance VueJS user interfaces in record time
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot