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
- Quick Webpack Wins (2)
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.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.
- Serialization (2)
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.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.
- Code Organization (4)
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.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 dedicatedHighlightVue component and tuck those initialization steps away from view.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.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.
- Further Techniques (1)
