Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Browse all series

Inertia and SPA Techniques

So you've mastered the basics of building an SPA with Laravel and Inertia? Nice work, but of course there's always more to learn. In this series, we'll review a variety of useful tips and techniques to simplify and clean up your single page applications. This includes everything from creating webpack aliases, to wrapping third party APIs, to leveraging Laravel's API resources. So what do you think? Ready to get started?

Progress

Series Info

Episodes
9
Run Time
1h 28m
Difficulty
Advanced
Last Updated
Mar 3, 2022
Version
Latest

Series Episodes

  1. Quick Webpack Wins (2)
    1. Import Aliases

      Let's ease into this series with something small and simple, but still quite useful. We'll leverage webpack aliases to make for cleaner JavaScript imports.
    2. Code Splitting Strategies

      While we're still on the subject of webpack, let's take a few moments to discuss some code-splitting strategies that you might consider - particularly when building medium-to-large applications.
  2. Serialization (2)
    1. Serialization Security Concerns

      Let's next move on to some potential security concerns that you might run into when converting a large server-side application to an SPA. You can of course no longer blindly pass an Eloquent model or collection to the client. Instead, it's vital that you be conscientious about every attribute you pass. Let's review a few options you might consider.
    2. Consider API Resources

      Next up, we can move on to API resources, which I leverage heavily in my own projects. Think of an API resource as a transformer class that converts an Eloquent model instance into its respective JSON representation. While models can do this automatically, resource classes provide a greater level of configurability.
  3. Code Organization (4)
    1. Wrap it in a Module

      Let's now move on to some suggestions and guidelines for how to structure and organize your code. In this episode, we'll learn how to extract initialization and configuration code for a third-party syntax highlighting library into a module with a smaller surface area.
    2. Wrap it in a Component

      The small syntax highlighting service we created in the previous episode is useful, but it still requires one too many steps to initialize. To fix this, let's create a dedicated Highlight Vue component and tuck those initialization steps away from view.
    3. Make it a Composable

      In this episode, we'll review another technique for organizing your code: Vue composables. You can think of composables as Vue 3's version of mixins - but on steroids. To illustrate this, let's add support for interacting with the Clipboard API.
    4. Make a Client-Side Model

      When building server-side applications, it's easy to open any Eloquent model and extend it with new behavior or affordances. The same, of course, is true on the client-side. You are not limited to basic scalars. When and if it makes sense, there's nothing keeping you from wrapping, for example, a set of user attributes in a dedicated class. Let's review how in this episode.
  4. Further Techniques (1)
    1. Options for Reducing Inertia Payloads

      Let's return to API resources and discuss situations where you may need to return a reduced payload to Inertia. It seems wasteful to return a full API resource if a particular view only requires a handful of its attributes. In this episode, I'll show you two options that you might consider for your own projects.

Continue Learning