Laravel, Vue and SPAs
In this series, come along as I build an "assets" website for Laracasts. Using Laravel as a backend, step-by-step, we'll pull in Vue and Vue Router to construct a practical and real-life single-page application.
Progress
Series Info
- Episodes
- 10
- Run Time
- 1h 24m
- Difficulty
- Intermediate
- Last Updated
- May 23, 2019
- Version
- Latest
Series Episodes
- Episodes (10)
The Skeleton
View the source code for this episode on GitHub.Building the Layout
In this episode, we'll construct the main layout for our assets website. To streamline this process, I'll pull in Tailwind and add it to my Laravel Mix build. Once installed, we can very quickly prepare the core site layout.One Component Per Page
We'll take a one-component-per-page approach to this website. This means, for each link in the sidebar, we need to create a companion Vue component. When finished, we'll review how to apply "active link" styling to the currently selected page.404 Pages
View the source code for this episode on GitHub.General Page Styling
With the basic structure in place, we can now move on to general page styling and tweaks.Lazy Loading Routes
To help improve performance, any route can be lazily-loaded by embracing Vue's async components and webpack's code-splitting feature. Don't worry: I hate confusing jargon, too. Let's break it down and review exactly when and why you might consider lazy loading certain routes in your app.Cross-Origin Resource Sharing (CORS)
Due to security concerns, it's not always so easy to make a cross-origin AJAX request to fetch a particular set of data. Instead, you'll often be met with the dreadedNo 'Access-Control-Allow-Origin' header is present on the requested resourceresponse. Let's discuss what this header means, and how we can fix it.Token-Based API Authentication
Now that you've learned how to make cross-origin AJAX requests, let's move on to the next step: API authentication. In this episode, we'll use a token-based approach as our "permission slip" for fetching user-specific data from the server.Hashed API Tokens
Let's next discuss how to generate hashed API tokens that Laravel can validate against. As of Laravel 5.8, we only need to visit theconfig/auth.php>file to enable hash-checking.Generating New Tokens
Any third party platform will need to offer users some way to revoke and generate new API tokens. Let's review a basic example of how you might do that.
