Snippets

Cleaning up code with dynamic method calling

Playing
Cleaning up code with dynamic method calling
17 mins6 years ago

Here's a popular pattern for diverging and dynamically calling a method based on an event, instantly cleaning up huge lists of conditionals.

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

Comments

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

Suggested courses

PHP

Easy Query Filters with Laravel Pipelines

Applying result filtering with query strings can mess up your controllers quickly. Let's reach for a solution using Pipelines, an undocumented but seriously powerful feature of Laravel. Every filter (e.g. only show activate users) will have its own class, neatly tucked away. We'll also cover testing, and see how this method makes isolated testing much easier.

6 episodes
35 mins
PHP

Installing Inertia from Scratch

The Laravel ecosystem gives us packages like Laravel Breeze and Jetstream which come ready set up with Inertia installed. But what if you want to install Inertia from scratch and build your own features on top of it? In this course, whether you're new to Inertia or not, we'll be covering getting Inertia set up on a completely fresh Laravel application. We'll walk through some nice additions like server side rendering, styling with Tailwind and installing Ziggy for named routes. To finish off the course, we'll build a simple app where we can post comments to a timeline, to bring everything nicely together!

14 episodes
1 hr 7 mins
PHP

reCAPTCHA with Laravel

Adding Google reCAPTCHA to a Laravel form isn’t too much trouble, but what happens when we want to re-use it for other forms? This course focuses on setting up reCAPTCHA using Alpine.js to fetch the token, and then middleware to verify the token based on a threshold in our config. We’ll add a Blade directive too, so we’re able to easily use reCAPTCHA for any forms in our Laravel apps — just by adding a couple of lines of code.

8 episodes
49 mins
PHP

Flexible Flash Notifications with Inertia

Flash notifications exist in almost every application. With Inertia, flashing notifications requires a bit more thought, and we're going to take this further and end up with a global notification plugin that just... works. By the end of the course, you'll have the ability to flash any type of notification, anywhere in your application, without repeating any code.

7 episodes
28 mins