Snippets

Short on time? Snippets are concise, free episodes that focus on a single goal

Trending

  1. 1
    Custom Laravel Jetstream Routes

    Need to tinker with Laravel Jetstream routes? In this snippet, we’ll take a look at disabling the default routes and registering them in our project codebase instead.

    Laravel
    4:01
  2. 2
    Gradient Headers with Tailwind

    By adding a simple utility class to Tailwind, we can achieve beautiful gradient colors for headers (or any text).

    4:19
  3. 3
    Enforcing referential integrity with the Laravel Schema builder

    Covering what referential integrity is, and how easy it is to enforce this to ensure tidy tables with integrity between relationships.

    PHP
    Laravel
    12:11

Featured

  1. 1
    Gradient Headers with Tailwind

    By adding a simple utility class to Tailwind, we can achieve beautiful gradient colors for headers (or any text).

    4:19
  2. 2
    Sortable models in Laravel Nova

    Let's take a look at how to implement effortless drag and drop sortable functionality in Laravel Nova, with the help of two packages.

    Laravel
    9:17
  3. 3
    Infinite Scrolling with Inertia

    Want super smooth, fast infinite scrolling in Inertia? In this snippet, we'll seed our database with a bunch of data and start building the solution, refactoring along the way until we perfect it.

    Inertia
    29:03

All snippets

Laravel
Trending Things Over Time With Laravel

Building a trending list of content with Laravel is actually pretty easy. In this snippet, we’ll take a look at how to create a list of trending articles over time, gradually decaying less viewed articles and pushing popular articles to the top. You’ll also be able to adjust the decay levels, and update the frequency of decay to tweak how sensitive your trending content is and how ‘realtime’ it appears.

7 mins
Inertia
Infinite Scrolling with Inertia

Want super smooth, fast infinite scrolling in Inertia? In this snippet, we'll seed our database with a bunch of data and start building the solution, refactoring along the way until we perfect it.

29 mins
Vue.js
SVGs with Vite and Vue

Adding SVGs to your Vue project doesn't need to be complicated. In this snippet, we'll take a look at using the vite-svg-loader package to make this a breeze, then clean things up by building our own component to handle loading SVGs effortlessly.

9 mins
Laravel
Inertia
Easy Pagination with Inertia

Pagination is essential for almost every application. Let's take a look at an easy way to render pagination links when using Inertia with Laravel and Vue.

16 mins
Laravel
Easily Register Laravel Observers with an Observable Trait

If you're using Eloquent model observers, you'll know registering them can break your flow. How about a convenient trait to automatically hook up the associated observer? Let's build it!

4 mins
Laravel
Testing Email Sending with Laravel Dusk

If you're browser testing with Laravel Dusk, chances are you haven't not been able to verify that emails are being sent – that's because Dusk runs in a browser environment. In this video, we'll set Dusk up to test sending an email, and show you how to use Laravel email fakes (and a helpful package) to test that an email has been sent.

12 mins
Laravel
Scheduling Actions on Models in Laravel

Need to perform actions on models at a future date and time? This snippet covers scheduling a command to monitor when an action needs to happen, then dispatching a queued job to handle your action. This allows you to do things like set a blog post live at a given date and time, or whatever functionality you need similar to this. Plus, it's actually pretty easy to set up!

14 mins
Laravel
Standardised Responses with Laravel Responsables

Building an API? The Laravel Responsable interface is absolutely essential for keeping your response structure the same across your entire application.

15 mins
Laravel
Sortable models in Laravel Nova

Let's take a look at how to implement effortless drag and drop sortable functionality in Laravel Nova, with the help of two packages.

9 mins
Vue.js
Debounce Input in Vue 3

If your app has a form that auto-saves as the user types, you'll need to debounce your input to avoid too many requests being sent to your API. Let's look at a quick and easy way to debounce input in Vue 3 as our form data changes.

7 mins
Laravel
Clear orderBy in Laravel

If you've already applied ordering to an Eloquent query, you'll have to 'reset' it if you need to change the order later on. Here's how!

4 mins
Laravel
Quick and Easy Nested Categories in Laravel

To solve a potentially unlimited amount of nested items like categories, you need more than recursive Eloquent relationships. Let's figure out how to easily build a tree of items with a single query, and use recursive Blade components to output the result.

20 mins
Alpine.js
Livewire
Global Modals with Livewire and Alpine.js

Learn how to create and trigger modals from pretty much anywhere in your app with Livewire and Alpine.js.

18 mins
Alpine.js
Alpine.js Auto Textarea Height

With a sprinkle of Alpine.js code, create a textarea that expands in height to fit content as a user types.

6 mins
Laravel
Switching Exposed Team IDs in Laravel Jetstream

By default, Laravel Jetstream’s team functionality exposes the team ID on the client side. If you’d like to switch it up it for any reason, here’s how.

14 mins
Laravel
Switching Exposed User IDs in Laravel Fortify Email Verification

By default, Laravel Fortify’s email verification functionality exposes the user ID in the verification email link. If you’d like to switch it up it for any reason, here’s how.

8 mins
Laravel
Custom Laravel Fortify Routes

Need to tinker with Laravel Fortify routes? In this snippet, we’ll take a look at disabling the default routes and registering them in our project codebase instead.

4 mins
Laravel
Custom Laravel Jetstream Routes

Need to tinker with Laravel Jetstream routes? In this snippet, we’ll take a look at disabling the default routes and registering them in our project codebase instead.

4 mins
Nuxt.js
Laravel
Nuxt Authentication with Laravel Sanctum

A quickstart guide to authenticating in Nuxt with a Laravel API using Sanctum. We’ll use the latest version of nuxt/auth, which includes native support for Sanctum as a provider.

14 mins
Building Tailwind with PostCSS

If Tailwind doesn’t support an integration for where you want to use it, build with PostCSS! This snippet gets you set up for development and production.

10 mins
Gradient Headers with Tailwind

By adding a simple utility class to Tailwind, we can achieve beautiful gradient colors for headers (or any text).

4 mins
Vue.js
Vuex
Build a Snackbar with Vue

A Snackbar is a small notification bar that pops up when a user performs an action. In this snippet, we’ll build a simple Snackbar in Vue for when you don’t want to pull in a package to handle it for you.

18 mins
Laravel
Using Blade Components for Page Titles

Blade components are useful for re-usable parts of your app, but they also work really nicely as app layouts. This makes it really clean to define elements like page titles for each of your pages.

10 mins
Laravel
Simple Custom Laravel Logging

This snippet walks you through setting up a separate log channel in Laravel, with its own file. We'll also tap into a custom log formatter to choose the output structure. Great for separating different kinds of logs.

7 mins
Vue.js
Laravel
Laravel Websockets with Vue

If you're using Laravel as a pure API and need to broadcast realtime events to your client with Laravel Websockets, this snippet covers using Laravel Echo in Vue to pick them up.

12 mins
Vue.js
Infinite Scroll with Vue

Here's how to implement a simple, clean pattern for infinite scrolling content in Vue. We'll refactor to make it more reusable, too.

21 mins
Alpine.js
Build an RSS reader with Alpine.js

Just for fun, let's build a simple RSS reader with Alpine.js that fetches and renders entries from a list of your chosen RSS publications.

14 mins
Laravel
Laravel Sanctum (Airlock) with Postman

You've got Sanctum up and running for authentication, but it's cookie based, so making requests to your API with Postman is a little more complicated. This snippet shows you how.

12 mins
Vue.js
Autosizing Textarea with Vue

In some cases, autosizing a textarea height as a user types makes sense. Here's how to do it with Vue.

13 mins
PHP
How middleware works

A low level overview of how middleware runs in your favourite framework. Starting with a simple app example, we'll build a middleware manager, add middleware to a stack, and run it.

20 mins
Slim
Using Whoops with Slim 4

Whoops gives you a much nicer way to display errors while you're building. In this snippet, we'll get Whoops installed with Slim 4.

8 mins
Laravel
Laravel Automatic Password Hashing

Using mutators to set properties in your models can really clean up your code. In this snippet, we'll look at an example of automatic password hashing and see how much tidier our controllers end up.

6 mins
Using Tailwind in Vue

A super quick guide to getting Tailwind installed, configured and working in a fresh Vue CLI project.

3 mins
Cleanly Setting Axios Base URL

Two methods for setting Axios' base URL in your projects instead of using it directly from config.

6 mins
Flutter
Flutter State Management with Provider

New to Flutter state management with provider? This snippet explains the core concepts and sets you up to get working with it.

11 mins
Nuxt.js
Tailwind with Nuxt.js

A quick start guide to getting Tailwind CSS working on your new or existing Nuxt projects.

7 mins
Laravel
Custom Laravel Collections

Custom Laravel collections add another level of fluency to your code. Let's take a look at a couple of examples to get you started.

15 mins
Vue.js
Inline Vue Validation in Under 10 Minutes

A quick setup guide for Vuelidate, a Vue inline validation library.

11 mins
Laravel
Grouping Laravel Notifications

Need to send a notification to a group of users without looping in your controllers? Let's abstract this away and write some nice clean code.

8 mins
Recreate our auto-hiding sliding navigation

Build a sticky navigation bar that automatically hides when a user scrolls the page, and reappears when they scroll back up.

9 mins
Vue.js
Dynamic Vue Components

Vue allows you to dynamically render components based on their names. This can help simplify your rendering and get rid of unnecessary logic from your templates. Here's an example using different notification types.

12 mins
Laravel
Magically invoking Laravel controller methods

Some controllers have one action. What should you name that action? Turns out you don't even have to.

2 mins
Vue.js
Nuxt.js
Using .env files with Nuxt

Using an .env file means keeping credentials out of your codebase and easily configurable between different environments. Doing this with Nuxt.js is easy as pie, let's check it out.

5 mins
Laravel
Automatically generating events and listeners in Laravel

A quick tip that'll save you huge amounts of time if your app is heavily event driven. Define Laravel events and listeners, then have the classes automatically generated for you.

1 min
Laravel
Refactoring chained where methods in Laravel

If you're chaining where methods when building queries with Eloquent, check out this simple refactoring tip.

2 mins
Laravel
Bootable traits in Laravel

If you need to register something within the boot() method of a model, here's a quick tip to do this within a trait if needed.

6 mins
Laravel
DigitalOcean spaces with Laravel

Here's how to use DigitalOcean spaces with Laravel's Filesystem. It's as easy as using S3!

4 mins
Laravel
The optional() helper callback

You may have used the optional() helper in the Laravel framework before, but did you know about the optional callback?

5 mins
Laravel
Using multiple keys for route model binding

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.

4 mins
Laravel
The Laravel tap() function

Let's walk through the Laravel tap() function, and how it might help clean up our code.

18 mins
Laravel
Dynamic breadcrumbs in Laravel

Build a partial to generate dynamic breadcrumbs based on your route structure, with plenty of refactoring along the way.

21 mins
Cleanly iterating over JavaScript objects

Ah, iteration. It's inevitable, so why not make it as clean as possible? We'll also dive into some of the complexities of looping in JavaScript.

5 mins
Laravel
Making Eloquent models 'LiveAware'

If your models share a 'live' property that you control, why not refactor this down to a single unit of functionality?

11 mins
Vue.js
Globally registering Vue components

A quick tip on globally registering all of your Vue components so you can just <Add /> them to your templates!

5 mins
Laravel
Automatically separate user file uploads in Laravel

Setting up Laravel's filesystem to automatically separate user's uploads into their own directory.

17 mins
Slim
Eloquent Observers in Slim 3

Eloquent works nicely in Slim, but model observers outside of Laravel require a little bit more work.

7 mins
PHP
Cleaning up code with dynamic method calling

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

17 mins
Laravel
Structuring Laravel for larger projects

You'll quickly outgrow the default Laravel structure as your app grows. Without much effort, let's look at some small changes that'll make a huge difference.

21 mins
Laravel
Impersonating users in Laravel

Allowing admins to sign in as other users is simple, but let's look at a more flexible and UX friendly solution.

14 mins
Laravel
Forcing HTTPS assets with Laravel

A common problem when using HTTPS with Laravel is JavaScript and CSS assets breaking. In this snippet, we'll discuss a quick solution to fix that.

8 mins
Laravel
Separate database for Laravel queues

Database queues in Laravel are quick to set up and work well for most projects. Let's tidy things up, and pop the queue tables in a database of their own.

7 mins
Laravel
Profiling JSON responses in Laravel

You might have used Laravel DebugBar to profile your query count and application speed, but how do we profile JSON responses? Let's find out!

9 mins
Vue.js
Filters in Vue.js 2.0

Filters were removed from Vue.js 2.0. Here's a quick tip on keeping the same feel in your new Vue.js applications

6 mins
Laravel
Exposing Laravel Homestead projects

Need to share a local project you're working on? Or test a webhook from a server? If you're using Laravel Homestead, we have you covered with this quick tip.

3 mins
Exposing your local web server

Need to share a local project you're working on? Or test a webhook from a server? We have you covered with this quick tip.

3 mins
PHP
Securing configuration

Do you store sensitive information directly in your code? That's fine for development, but if you're pushing to source control or production, there's better way.

13 mins
PHP
Design Patterns: Singleton Pattern

Although it's an anti-pattern, let's take a look at the singleton pattern and why we probably shouldn't use it.

15 mins
PHP
Custom session handlers

How to switch out your standard PHP session handler and use the database instead.

20 mins
Slim
PHP
Custom 404 views with Slim 3

Dive into how missing routes are handled, and then build your own handler, rendering a view in place of Slim's default response.

8 mins
PHP
Random numbers and bytes with PHP7

Forget the methods you've used before to generate random numbers and strings. PHP7 now supports it out the box!

5 mins
PHP
Design Patterns: Adapter Pattern

The adapter pattern is a very easy pattern to understand. In fact, you've probably used it without knowing!

6 mins
PHP
Design Patterns: Decorator Pattern

Ready for some decorating? Grab your tools and let's learn about the decorator pattern.

14 mins
PHP
Laravel
Custom Pagination Presenters with Laravel

You might need to change the way your Laravel pagination links are displayed. Well, here's how.

18 mins
PHP
Laravel
Enforcing referential integrity with the Laravel Schema builder

Covering what referential integrity is, and how easy it is to enforce this to ensure tidy tables with integrity between relationships.

12 mins
PHP
PSR-4 Autoloading with Composer

A quick guide to downloading and PSR-4 autoloading with Composer.

6 mins
PHP
Laravel
Laravel Route Model Binding

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.

3 mins
PHP
So, what's an interface?

Interfaces are used in development a lot, but why make a class adhere to an defined interface? Let's take a look at an example of how this is useful.

8 mins
Slim
PHP
Configuration with Slim 3

Easily set up powerful, flexible configuration within Slim 3 and make it easier to switch your application settings.

11 mins
PHP
Quickly converting an array to an object in PHP

A useful tip for when you need to quickly cast an array to an object.

3 mins
PHP
Fun with Ternery Operators in PHP

How ternery operators can clean up your code and speed up development.

5 mins
PHP
Using PHP's Built-In Web Server

Did you know PHP has a built-in web server we can run from the command line? Let's take a look at how it works.

6 mins
PHP
Flattening A PHP Multidimensional Array

A couple of methods you can use to flatten a multidimensional array with PHP. The first method looks at a more verbose method of looping through array items and self calling a function/method, and the second looks at using standard PHP classes to make it a bit cleaner.

12 mins
PHP
Generate Fake Data with PHP using Faker

Speed up development and use Faker to generate fake data, like words, paragraphs, names, email addresses, and so much more! Here, we look at seeding a database with 100 records of data at the click of a button.

14 mins
PHP
Generate Scannable QR Codes With PHP

Here's a super quick way to generate QR code images for scanning.

12 mins
Sniff Out Unclean Code with PHP CodeSniffer

Ever wanted to run a command to check your code against a particular standard? PHP CodeSniffer lets you do that right from the command line!

9 mins
Take Photos With Your Webcam In Your Browser

Harness the power of WebRTC and Canvas and capture photos from your webcam inside your browser. We build a webcam stream, and a button to take a photo that can be downloaded.

16 mins
Emmet - The Essential Toolkit For Web Developers

Learn how to dramatically speed up your workflow by generating large amounts of HTML using CSS style selectors. In this video, we specifically look at generating HTML, but Emmet offers other functionality to help you work faster.

23 mins
Responsive CSS Sticky Footer

A super quick hack to create a responsive sticky footer.

4 mins