Git Product home page Git Product logo

k2so-dev / laravel-nuxt Goto Github PK

View Code? Open in Web Editor NEW
124.0 5.0 22.0 2.79 MB

Laravel and Nuxt.js boilerplate designed for development with maximum API performance, ready-made authorization methods, image uploading with optimization, user roles, device management

License: MIT License

PHP 75.25% TypeScript 5.35% Vue 18.96% CSS 0.24% Blade 0.20%
laravel nuxt nuxt-boilerplate nuxt-ui nuxt3 sanctum sanctum-authentication tailwindcss vue vue3 laravel-boilerplate laravel-sanctum boilerplate laravel-vue starter-kit vue-ssr laravel-nuxt laravel11 breeze jetstream

laravel-nuxt's Introduction

preview

Laravel Nuxt Boilerplate

FOSSA Status GitHub Workflow Status CodeQL

The goal of the project is to create a template for development on Laravel and Nuxt with maximum API performance, ready-made authorization methods, image uploading with optimization and ready-made user roles.

Features

  • Laravel 11 and Nuxt 3
  • Laravel Octane supercharges your application's performance by serving your application using high-powered application servers.
  • Laravel Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more.
  • Laravel Sanctum Token-based authorization is compatible with SSR and CSR
  • Laravel Socialite OAuth providers
  • Laravel Sail Light-weight command-line interface for interacting with Laravel's default Docker development environment.
  • Spatie Laravel Permissions This package allows you to manage user permissions and roles in a database.
  • UI library Nuxt UI based on TailwindCSS and HeadlessUI.
  • Pinia The intuitive store for Vue.js
  • Integrated pages: login, registration, password recovery, email confirmation, account information update, password change.
  • Temporary uploads with cropping and optimization of images.
  • Device management
  • ofetch preset for working with Laravel API, which makes it possible use $fetch without having to resort to custom $fetch wrappers.

Requirements

Installation

Standalone

  1. composer install && yarn install
  2. cp .env.example .env && php artisan key:generate && php artisan storage:link
  3. php artisan migrate && php artisan db:seed
  4. php artisan octane:install
  5. php artisan octane:start --watch --port=8000 --host=127.0.0.1
  6. yarn dev

Docker Deploy (Laravel Sail)

Laravel Sail is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.

At its heart, Sail is the docker-compose.yml file and the sail script that is stored at the root of your project. The sail script provides a CLI with convenient methods for interacting with the Docker containers defined by the docker-compose.yml file.

Laravel Sail is supported on macOS, Linux, and Windows (via WSL2).

  1. Installing Composer Dependencies
docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v "$(pwd):/var/www/html" \
    -w /var/www/html \
    laravelsail/php83-composer:latest \
    composer install --ignore-platform-reqs
  1. Configuring A Shell Alias (Optional)
alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'

To make sure this is always available, you may add this to your shell configuration file in your home directory, such as ~/.zshrc or ~/.bashrc, and then restart your shell.

  1. sail up
  2. sail yarn install
  3. sail yarn dev

Read the full Laravel Sail documentation to get the best user experience

Upgrade

Standalone:

npx nuxi upgrade
composer update

Sail:

sail npx nuxi upgrade
sail composer update

Usage

Nuxt $fetch

To work with the api, the default path is "/api/v1". All requests from Nuxt to the Laravel API can be executed without wrappers, as described in the Nuxt.js documentation. For example, the code for authorizing a user by email and password:

<script lang="ts" setup>
const router = useRouter();
const auth = useAuthStore();
const form = ref();
const state = reactive({
  email: "",
  password: "",
  remember: false,
});

const { refresh: onSubmit, status } = useFetch("login", {
  method: "POST",
  body: state,
  immediate: false,
  watch: false,
  async onResponse({ response }) {
    if (response?.status === 422) {
      form.value.setErrors(response._data?.errors);
    } else if (response._data?.ok) {
      auth.token = response._data.token;

      await auth.fetchUser();
      await router.push("/");
    }
  }
});

const loading = computed(() => status.value === "pending");
</script>
<template>
  <UForm ref="form" :state="state" @submit="onSubmit" class="space-y-4">
    <UFormGroup label="Email" name="email" required>
      <UInput
        v-model="state.email"
        placeholder="[email protected]"
        icon="i-heroicons-envelope"
        trailing
        type="email"
        autofocus
      />
    </UFormGroup>

    <UFormGroup label="Password" name="password" required>
      <UInput v-model="state.password" type="password" />
    </UFormGroup>

    <UTooltip text="for 1 month" :popper="{ placement: 'right' }">
      <UCheckbox v-model="state.remember" label="Remember me" />
    </UTooltip>

    <div class="flex items-center justify-end space-x-4">
      <NuxtLink class="text-sm" to="/auth/forgot">Forgot your password?</NuxtLink>
      <UButton type="submit" label="Login" :loading="loading" />
    </div>
  </UForm>
</template>

In this example, a POST request will be made to the url "/api/v1/login"

Authentication

useAuthStore() has everything you need to work with authorization.

Data returned by useAuthStore:

  • logged: Boolean, whether the user is authorized
  • token: Cookie, sanctum token
  • user: User object, user stored in pinia store
  • logout: Function, remove local data and call API to remove token
  • fetchUser: Function, fetch user data

Nuxt Middleware

The following middleware is supported:

  • guest: unauthorized users
  • auth: authorized users
  • verified: users who have confirmed their email
  • role-user: users with the 'user' role
  • role-admin: users with the 'admin' role

Laravel Middleware

All built-in middleware from Laravel + middleware based on roles Spatie Laravel Permissions Middleware

Examples

Route list

routes

Demo

demo.mov

Links

License

FOSSA Status

laravel-nuxt's People

Contributors

fossabot avatar k2so-dev avatar martin-ro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laravel-nuxt's Issues

HTTPS Redirect

All my requests are going with https locally, is there any way to change this?

image

Forge deployment

Hi,

thanks for this great starter package. I've been playing around with it locally.

Would you mind explaining how to deploy this setup with forge? As this is a monolith how'd you run octane and also serve the frontend with nuxt?

Cheers

Nuxt development environment is so slow

Hi,

Is it just me or is developing with nuxt extremely slow? When I hit save it takes 10 seconds every time before I even see it on my screen. When I re-run npm run dev it takes ages before the dev environment is ready.

How can we make a SSR call?

Hi,

How can we make a SSR call?

When i try this:

const { workspaces: workspaceData } = await $fetch<any>("workspaces");

It's always client side. When I add ssr:

const { workspaces: workspaceData } = await $fetch<any>("workspaces", {
       server: true
});

https://nuxt.com/docs/getting-started/data-fetching

It's not working , and still making a client side call (I have SSR enabled in my nuxt.config file).

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.