Snippets

Using multiple keys for route model binding

Playing
Using multiple keys for route model binding
4 mins5 years ago

By default, Laravel uses one key for route model binding lookup. When you need to use two or more, this is how to do it.

Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.

Suggested courses

Laravel

Build an Appointment Booking System With Inertia

Building an availability calendar and booking system is a notoriously difficult problem to solve. That’s exactly what we’re going to cover in this course. Step by step, we’ll build an appointment slot generator that calculates availability based on employee schedules, employee’s booked time off, the length of service chosen, existing appointments, and cancelled appointments. For maximum flexibility, we’ll also allow multi-employee availability checks, so we’ll be able to see every employee who can perform a service (and their available slots). To finish up, we’ll create an entire booking flow with Inertia (using Vue), including a beautiful booking calendar that shows detailed availability across multiple dates, the ability to choose a time slot — and finally the ability to book an appointment. Phew. We’ve got a lot to learn — let’s build a booking system with Inertia!

39 episodes
5 hrs 0 mins
Laravel

Crop and Upload Profile Photos with Livewire

Using Livewire, Alpine and Cropper.js (or any cropping library), we’ll create an embeddable form field for users (or any other model) to upload profile photos. The form element will launch a modal, where users can crop and adjust their profile photo, before being able to preview and save the cropped image — or clear everything out and start again. You’ll learn: - How to launch modals in Livewire - How to use Cropper.js with Alpine - How to resize images on the backend with the spatie/image package - How to pass data between Livewire components

10 episodes
43 mins
Laravel

Custom Laravel Query Builders

Using Eloquent query scopes in your project? Consider swapping them out for custom query builders. Custom query builders are model-specific, class-based builders that provide better organisation, IDE autocompletion, and more. We'll start this course by defining some standard scopes, refactor them, and discuss the benefits of custom builders. This course is for you if: - You're using query scopes, but they're bloating your models - You're working in a team and need more organisation in your project - You haven't used query scopes and want a primer, plus an alternative

4 episodes
23 mins
Laravel

Liking Things in Laravel with Redis

Let’s skip the database and build the ability to like any model in Laravel, using Redis. Traditionally you’d reach for the database for this kind of thing, but as you load more models and start performing checks within relationships — things begin to slow down. With a key-value store like Redis, tracking users who have liked comments (or anything) keeps everything ridiculously fast.

6 episodes
21 mins
Laravel

Build a Livewire CSV Importer

Let's build a powerful CSV importer with Livewire, completely from scratch. This can handle millions of rows, be reused for multiple models, and by using job batches, doesn't require the browser to be open. This course is for you if: - You need a robust importer component for your models that you have full control over - You want to brush up on some advanced Livewire concepts - You want to learn about job batching and queues in Laravel

25 episodes
2 hrs 20 mins