Lifetime access is $100 off. Available for a limited time.Join here →
Snippets

Laravel Route Model Binding

Playing
Laravel Route Model Binding
3 mins8 years ago

Tidy up your code drastically by binding models to routes and automatically fetching a model by it's primary key when you access a URI like /users/1.

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

Comments

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

Suggested courses

Laravel
PHP

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
PHP

Build a URL Shortener with Volt and Folio

Volt is a functional API for Livewire that allows you to build Livewire components in a single file, alongside Blade templates. Pairing this with automatic route creation using Laravel Folio gives us a serious productivity boost. So, let’s build a URL shortener while learning how Volt and Folio work!

10 episodes
53 mins
Laravel
PHP

Authentication with Laravel Sanctum and Vue

Learn how to authenticate with a Laravel API from Vue using the Composition API. We'll start by setting up a fresh Laravel project with Sanctum and Fortify, configure everything step-by-step, and then implement the ability to authenticate from Vue with a simple auth module — thanks to the flexibility of the Composition API. In the second half of the course, we’ll create our own beautiful starter kit with more features, including registration and middleware to protect routes.

0 episodes
0 mins
Laravel
PHP

Laravel Model Pruning

Database tables filling up? Let's learn how to quickly and automatically remove records with Laravel's native Pruning functionality. Before Laravel 8.50.0, we'd have to take care of this manually. Now, it's as simple as adding a trait, a query builder, and running an Artisan command. We'll also dive into what's happening behind the scenes to understand how this works.

6 episodes
23 mins
Laravel
PHP

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