Setup a Pinia store using Vue3 and Laravel 9.x with Inertiajs SSR

53952.png

Yo yo

 rotating-icons.gif

Can Chat GPT really answer this question? Of course.

Sometimes I like coming up with some outlandish obscure programming question to really test Chat GPT. As much as I hated on it during it’s come-up, I am still always surprised by how accurate or close it gets to a real working answer.

Hey Mr. GPT. Lets say you are using laravel + inertiajs with SSR enabled. Add Pinia stores to ssr.js file.

To add Pinia stores to the SSR.js file in a Laravel Inertia.js app with SSR enabled, you can use the following steps:

  1. Import the Pinia store in your component:
import { useStore } from '@inertiajs/inertia-vue' export default { setup() { const store = useStore() return { store, } }, }
  1. Pass the Pinia store to the Inertia component in your SSR.js file:
import { InertiaApp } from '@inertiajs/inertia-vue' export default (context) => { return new Promise((resolve, reject) => { const { app, store, isServer } = createApp() resolve( new Vue({ store, provide: { page: () => context.page, }, render: (h) => h(InertiaApp, { props: { initialPage: context.page, resolveComponent: (name) => { return import(`@/Pages/${name}`).then((module) => module.default ) }, }, }), }) ) }) }
  1. This is a basic example of how to pass Pinia stores to the SSR.js file in a Laravel Inertia.js app. You can adjust this code to fit your specific needs.

So, what do you think about that?

Surely you have heard of Laravel Breeze & Jetstream if you know about Inertia Js. I really was proud of my PR that upgraded Laravel Mix to Vite in their slick demo; Ping CRM. Only thing was, someone had already submitted a PR. Who’s is better though?

What if you wanted to use Strapi as an API? That may be a post for another time. ..unless ChatGTP knows how?

Here’s an outline of how to implement user authentication, roles, permissions, and content CRUD API with Strapi and Vue3 and vue-router:

  1. Create Strapi API:
  • Install Strapi and create a new project
  • Use Strapi to create user authentication, roles, and permissions
  • Create content types in Strapi for the content you want to manage
  • Use Strapi’s RESTful API to CRUD content in your Vue3 application
  1. Create Vue3 frontend:
  • Install Vue3 and create a new project
  • Integrate vue-router for routing in your application
  • Implement user authentication using Axios to make API calls to Strapi for authentication and authorization
  • Use Vuex for state management and to store user information, authentication status, and role/permission information
  • Use vue-router guards to protect routes based on user authentication status and role/permission information
  • Use Axios to make API calls to Strapi to retrieve and modify content

This is a high-level overview of how to implement user authentication, roles, permissions, and content CRUD API with Strapi and Vue3 and vue-router.

You will need to write code to implement the specific details and tailor the implementation to your specific requirements.