Master Laravel with hand-curated daily tips

Laravel documentation is top-notch, but it's impossible to cover everything. Mastering Laravel is not just solving problems when you're stuck - it's also about becoming the best Artisan and programmer you can be.

We're excited to share a daily email with you that you can read in less than 2 minutes. Oh, and if daily is too often - don't worry - you can opt into weekly digests instead.

What are you waiting for?!

Or check out the archive below to be convinced.
I've been subscribed to this newsletter for less than a week, and I already received some advice that I was able to instantly implement into my daily work. samuel Samuel Pedraza

Daily Tips Archive

We've been cranking out tips for a while now. Can you believe there are 183 of them?! Keep on scrolling to see what you may have missed below.

2024-04-24

Is now the right time to clean up this data?

Keep a realistic outlook
2024-04-23

Using the stricter assertSame check with collections

Without making the test more complex
2024-04-22

Should this be a collection or an array?

Use the right tool for the job
2024-04-19

A strategy for testing permissions logic

And avoiding false positives
2024-04-18

Easier test coverage for complex API resources

And the tests are fast too
2024-04-17

Rate limiting down to the second

Important for high-traffic applications
2024-04-16

Adding rules to an extended form request

It's all just arrays
2024-04-15

What is the difference between the asset helpers?

And which one should you use?
2024-04-12

What is the longest valid email address?

And how does this impact validation rules?
2024-04-11

The life cycle of database hosting

Start simple and grow as needed
2024-04-10

Preventing performance surprises with Laravel migrations

Keep your system healthy
2024-04-09

Is there a performance penalty in MySQL for inserting a column?

The answer is nuanced
2024-04-08

Passing arguments to a partial mock's constructor

You can't use Laravel's mock helper
2024-04-05

Avoid unnecessary work when querying relationships

Keep your database happy
2024-04-04

How would you test code that uses the `old()` helper?

And why you might want to
2024-04-03

A better way to schedule commands

Avoid magic strings
2024-04-02

Partial mocks don't run constructors

At least by default...
2024-04-01

How to troubleshoot S3 filesystem issues

Silent failures are the worst
Book cover for A Little Bit of Laravel

Prefer a little bit more meat with your tips?

You're in luck! This ebook contains tips and tricks that are quick and easy to apply but make a noticeable improvement in any Laravel app. Dig in a little bit deeper with larger code samples and deeper explanations.

March, 2024

2024-03-29

Understanding how caching works in GitHub Actions

Keep CI running fast
2024-03-28

Are you really going to need that abstraction?

No really, are you sure?
2024-03-27

Forcing all API requests to accept JSON

Avoid annoying errors
2024-03-26

How to use Pusher with private encrypted channels

Important when dealing with sensitive data
2024-03-25

An easy way to test UUIDs

Laravel has you covered
2024-03-22

Understanding the order of authorization and model binding

And why you shouldn't just flip the order
2024-03-21

A trick for geolocating US postal codes

It's dumb, but it works
2024-03-20

How to step debug a queued job

For those times when dd is not enough
2024-03-19

Cleaning up deprecated warnings during a database migration

Don't ignore it
2024-03-18

Monitoring progress of a big database import

Without this, it feels like it takes forever
2024-03-15

A good rule for when to create a factory state

Make your tests more readable
2024-03-14

Should you change app code for a test?

It depends on why you're changing it
2024-03-13

Loading a SQL backup without altering your configuration

Sometimes data is messy
2024-03-12

Why I always add a primary key to many-to-many tables

Even when Laravel doesn't require it
2024-03-11

Make sure your listeners are wired up

Without this simple test, nothing else matters
2024-03-08

How to set CORS headers for built assets

And do it efficiently
2024-03-07

Something to know if serving scripts for other sites

Especially if you moved to Vite
2024-03-06

Loading relationships inside a queued job

Do it the Laravel way
2024-03-05

A better way to drop a unique index

It involves less guesswork
2024-03-04

Why pagination sometimes has overlapping pages

A deeper look inside the database
2024-03-01

Sharing redirect logic between controller actions

Without resorting to messy hacks

February, 2024

2024-02-29

What is the point of design patterns?

And have you fallen asleep yet?
2024-02-28

Manual testing still has its place

Put yourself in the shoes of your users
2024-02-27

Ignoring files per environment with Docker

And why you might want to do this
2024-02-26

Quickly viewing test file structure

Another reason I like patterns
2024-02-23

Picking a good test value

And avoid flaky tests
2024-02-22

Pay attention to analytics

There can be some interesting insights
2024-02-21

Consistent test organization

I like patterns
2024-02-20

How we use migrations during early product development

When the schema changes quickly
2024-02-19

Simple rules for writing authorization logic

A little bit of structure goes a long way
2024-02-16

One place I avoid constructor property promotion

Just to keep the intent clear
2024-02-15

Move that logic out of your view

How much is too much?
2024-02-14

Alpha validation might not be doing what you think

It certainly surprised me the first time I bumped into it
2024-02-13

Avoid changing your code purely for a test

Even if it's just to make a property public
2024-02-12

Get better auto-complete from your factories

And reduce the need for @var docblocks
2024-02-09

Watch out for this when testing Artisan commands

A weird reason for a failing test
2024-02-08

A clean approach to testing events and listeners

Focus on what each thing should do
2024-02-07

Another reason I like fillable instead of guarded

Every little bit helps
2024-02-06

A safer way to check model strictness in production

Without annoying your users
2024-02-05

Why does Laravel offer a max password length validation rule?

Doesn't hashing make this irrelevant?
2024-02-02

Composer scripts and Valet isolate

Something to be aware of
2024-02-01

Is it worth switching to another tool?

And how do you know when it's the right time?

January, 2024

2024-01-31

Being explicit when something should not queue

A simple way to clearly communicate intent
2024-01-30

Absolute paths and the Vite asset helper

Want to laugh at me? It's ok.
2024-01-29

Don't become numb to pain in your project

You can make it better!
2024-01-26

Why might you want to forget a route parameter?

And how does it work?
2024-01-25

Inspecting files in a Docker container

And easily spotting what changed
2024-01-24

Considerations when cleaning up a big table

Without causing downtime or making production slow
2024-01-23

A measured approach to using Larastan

More isn't always better
2024-01-22

How to test that a model wasn't changed

In a very simple way
2024-01-19

Running HTTP requests right inside your editor

I promise I'm not getting paid by JetBrains
2024-01-18

How we use seeders in our application

And why we rarely use them for testing
2024-01-17

Another nice feature for local pull request review

It's even nicer than GitHub's UI
2024-01-16

Eager loading, but only if you really need to

Since we want to reduce the number of queries
2024-01-15

Route binding with two different models

While still leveraging the framework
2024-01-12

Stop using $request->get()

There is a better way
2024-01-11

Don't reinvent features that Laravel already has

For example, soft deletes
2024-01-10

Vite Hot Module Replacement and setInterval

And a workaround if you really need one
2024-01-09

What is the difference between boot and register in service providers

Where do I put this code?
2024-01-08

Even GitHub comments have version control

And it occasionally helps you win arguments
2024-01-05

Failing tests give you confidence

Not just knowing it fails, but why
2024-01-04

Don't just get mad at some tech, dig in and learn

Once you learn it, then you can complain
2024-01-03

Use factories to make your tests more readable

Only include relevant details in your test setup
2024-01-02

One situation where it is useful to make more than one request in a test

Don't abuse this, but here's one case I think is okay
2024-01-01

Using factories with more than one relationship

Sometimes you can't follow the typical naming convention

December, 2023

2023-12-29

Redirect routes match all HTTP verbs

If you need to be more precise, here's a better way
2023-12-28

Routes resolve differently when cached

But tests can help you catch the issue
2023-12-27

The benefits of caching in CI

And it's not for performance reasons
2023-12-26

Don't cache routes or views locally

Great for production, but trouble for development
2023-12-25

View source always makes a new request

I forget this like once a year
2023-12-22

How clear coding rules can free up your team

Have the debate once, then move on
2023-12-21

Making a case for consistency

And the importance of a good README
2023-12-20

Why the nullable validation rule is useful

Sometimes code is for your team, not just the PHP runtime
2023-12-19

Why we don't use SQLite for tests

Faster isn't always better
2023-12-18

When it might be ok to use a mixed type

It serves a useful purpose
2023-12-15

Using writing to think through a problem

This has saved me many times when I felt stuck
2023-12-14

Are you writing script definitions in Composer?

If not, we highly recommend it!
2023-12-13

Why we don't use return types on controller actions

But we do like return types in general!
2023-12-12

How to route based on the requested domain

Very useful if you serve multiple sites out of the same Laravel app
2023-12-11

Keep your testing database separate from development

Understanding how phpunit.xml works opens up many possibilities
2023-12-08

Don't rely on key ordering with MySQL JSON values

This behavior caught me by surprise
2023-12-07

Different approaches to upgrading to a new major Laravel version

And we explain the pros and cons of each
2023-12-06

Be consistent with composer scripts in CI

Keep it simple and save yourself some trouble
2023-12-05

Why we like minimal seeders for tests

Getting this right will make your tests so much easier to maintain
2023-12-04

You don't need to manually run seeders in your tests

Laravel is constantly making things nicer
2023-12-01

A surprising issue with the Auth user and tests

Knowing how this works helps you avoid false failures in your tests

November, 2023

2023-11-30

Lazy loading protection does not catch all N+1 queries

I discovered this one the hard way
2023-11-29

Should you be able to override coding standards locally?

And why am I even asking this question?
2023-11-28

A simple approach to localization using middleware

We used this on a recent project and it worked great.
2023-11-27

How to rate limit by IP behind a Cloudflare proxy

If you don't do this, your app could actually start blocking Cloudflare traffic.
2023-11-24

Don't take it personal if your contribution is rejected

You had a good idea and submitted it, but then the project rejects it. Now what?
2023-11-23

Maybe you don't need to write code this time

And using a no-code tool may even give you more empathy for users of your app
2023-11-22

How to reference a PHP CodeSniffer ruleset in EasyCodingStandard

This simple addition can make it much easier to migrate between tools
2023-11-21

How does LetsEncrypt work behind Cloudflare?

If we use a proxy like Cloudflare, will it impact our ability to issue LetsEncrypt certificates?
2023-11-20

Considerations when eager loading resource collections

Check out a subtle bug that avoided notice for a while, and how tests eventually helped us.
2023-11-17

The right way to fix double encoding in Blade components

There is a lot of bad advice out there on this topic. Here's a better approach.
2023-11-16

Version untracked files with PhpStorm

Another very handy use for PhpStorm's Local History feature
2023-11-15

Enforcing Horizon auth in local

Is this overkill? Or does it give you more confidence in your application?
2023-11-14

Cloudflare, Laravel, and TLS

Double check this setting to save yourself some trouble
2023-11-13

A good rule around "down" migrations

Some would say don't bother to write "down" migrations. I argue that if you do, you should follow this rule.
2023-11-10

Use the right tool for the job

You can still have your favorite, but it's good to see what else is out there
2023-11-09

Should you manage roles and permissions with a UI?

It's tempting to let non-developers manage this data, but is it a good idea?
2023-11-08

Understanding how Laravel sessions work

If we don't know how something works, it's more confusing when things behave differently than expected.
2023-11-07

Using workarounds without creating a mess

Sometimes a workaround is unavoidable, but how can you avoid them from piling up technical debt?
2023-11-06

Dealing with messy JSON

Sometimes API do unspeakable things and we have to work around it in our app
2023-11-03

The value of a quick code demo

Sometimes it's more effective to show than tell
2023-11-02

Don't get defensive during code review

Sometimes even a small observation can lead to a big improvement
2023-11-01

How to assert a Laravel job is delayed

I've seen a lot of convoluted approaches to this, here's a drop-dead simple way to do it.

October, 2023

2023-10-31

Ever need a different git setting per repo?

Maybe you have one git account for work, and one for open source. How do you make sure the right author is used in each repo?
2023-10-30

Keep your code consistent

Ever find 5 different ways of doing something in a single codebase? Here's an approach to minimize that.
2023-10-27

How to get rid of HEIC files in your app

And it makes your app easier to use for non-iPhone users too
2023-10-26

The changing value of books throughout your career

Perhaps that book you thought was useless 5 years ago is exactly what you need today.
2023-10-25

Actually read the whole error message

This seems really simple and obvious, but I've been burned in the past not doing this myself.
2023-10-24

How much detail should you include in error messages?

Error messages are part of user experience.
2023-10-23

Is it time to abstract this?

You spot two things in your app that are mostly the same. Is that an automatic refactor?
2023-10-20

How do you test middleware?

Middleware can be a tricky thing to test. Here's what I did in a recent project.
2023-10-19

Document before automating

As devs, sometimes we rush to coding a solution. But there's an important step that should come first.
2023-10-18

A simple way to avoid multiple lookups within a request

Traditional caching comes with its own set of complexities. Here's a simple way to use basic PHP instead.
2023-10-17

Joins in Eloquent? How?

Sometimes you need a join for performance or sorting by relations. Here's a way to do that without giving up Eloquent.
2023-10-16

Ship something every day

There's value in shipping something, anything, at least once a day, even on a bigger feature.
2023-10-13

Is sleep in a test always bad?

You might think adding sleep to a test is a dirty hack, but it's not always a bad thing.
2023-10-12

Some reasons to write a down method in your migrations

And it's probably not the reason you think.
2023-10-11

Use custom Mockery matchers for better Laravel assertions

Clean up your tests, especially when passing models as arguments
2023-10-10

What does INT(11) mean in MySQL?

Here's a hint: it has nothing to do with length
2023-10-09

How do you insert a new column at the beginning of a MySQL table?

And more importantly, why would you want to?
2023-10-06

Be careful ordering columns in a migration

Laravel migrations let us insert a column in a specific position in a table, but it's not always a good idea.
2023-10-05

Applying a class to a Markdown link

Ever wish you could add a CSS class to a Markdown link? Here's how I did it.
2023-10-04

Don't forget to pin PECL extensions

We pin Composer packages and PHP versions, but what about PECL extensions?
2023-10-03

How to make the AWS SDK much smaller

Only need a small portion of the AWS SDK, and wish you could make it a lot smaller?
2023-10-02

Do you really need to install that SDK?

If you're integrating with a third-party API, you may not need to bring in a giant SDK.

September, 2023

2023-09-29

Cache Larastan results in Github Actions

Larastan is a great tool, but it can slow down your CI pipeline. Here's how to cache the results to make each run faster.
2023-09-28

Managing a micro-manager

It's frustrating to have a client or co-worker attempt to micro-manage you. We share some tips on how to make the working relationship better.
2023-09-27

Drop unneeded steps in CI

This might seem pretty obvious, but it's easy to forget to remove steps from your CI pipeline when they are no longer needed.
2023-09-26

Keep your Laravel CI pipeline running fast

CI pipelines tend to get slower over time, the more we add to them, and the bigger our project grows. Keeping an eye on this is important.
2023-09-25

Knowing when to keep it simple

We take pride in building things "the right way", but there is a balance to strike with simplicity.
2023-09-22

Should we write tests for this one-time command?

I'm a huge proponent of writing tests, but is there ever a valid time to skip them?
2023-09-21

A good use case for the Eloquent sole() method

The sole() method has been around for a while, but I don't use it very much. Here's one place I found it useful.
2023-09-20

The benefit of one-time commands

Is there any reason to build a Laravel command you only plan to use one time? Let's consider a few benefits.
2023-09-19

Do we really need to build this feature?

Before diving into the code and cranking out a feature, sometimes it's useful to consider if we really need to build it at all.
2023-09-18

Easily find specific code usages in PhpStorm without regex

Regexes in search logic are powerful, but this tip will supercharge your code searching without needing to get too fancy.
2023-09-15

Understanding how Laravel view assertions work internally

No one likes a passing test when the actual logic is wrong. Here's how to make sure your view assertions are actually testing what you think they are.
2023-09-14

Local history in PHPStorm

If you already have git, why would you use the local history feature in PHPStorm?
2023-09-13

Be careful when using assertViewHas with null

Laravel's assertViewHas method doesn't work for null values. Here's how to test for them.
2023-09-12

When to pull in top-level dependencies

If Laravel already requires a package, is there ever a reason to install it into your project directly?
2023-09-11

Use GitHub issue templates to save time

Having a template not only makes issue creation easier, but also more consistent.
2023-09-08

What if every Composer package had a fee?

An interesting thought experiment that might influence how many packages you pull into your project.
2023-09-07

How to override PHPStorm file types

PHPStorm allows you to override the file type, giving you different syntax highlighting and auto-complete prompts.
2023-09-06

When might you render a Blade template inline?

This isn't a feature I reach for frequently, but it's good to know it exists. Here is one use case where we found it quite handy.
2023-09-05

How to make a bug fix way more valuable

Fixing bugs is important, but by taking just a little more time you can make your app much more resilient
2023-09-04

Don't explicitly install dependencies if you don't need to

Pay attention to the dependencies Laravel or other packages are already bringing in. You may be pinning them to an older version without realizing it.
2023-09-01

Take time to make things better

Look for opportunities to make things just a little bit nicer than you found them.

August, 2023

2023-08-31

Tools should work for you, not boss you around

Ever have a day where you're "fixing the squiggles" in your editor and feel like the code got worse? Let's talk about how to avoid that.
2023-08-30

Try not to make things worse

You know those parts of a codebase that feel "not great"? Be mindful to not further entrench those bad decisions.
2023-08-29

Are fast queries always good?

I mean, yeah! Right? Well, there's more to the story...
2023-08-28

Clean up dead git branch references automatically

When you merge a branch in GitHub, the reference to it is still in your local repo. How can you clean those up automatically?
2023-08-25

A scenario using events and observers together

Sometimes it's useful to pair events and observers together. Let's look at one real-world example.
2023-08-24

When should you use events and observers?

Laravel events and observers seem to do very similar things. So when would you use one over the other?
2023-08-23

How do you know if something is slow in production?

The tools we used for finding slow code in development are not suitable for production. So how can we find slow code there?
2023-08-22

Something slow? It's probably the database.

The absolute number one cause of slow code is the database. Laravel makes fixing some of the common issues very easy.
2023-08-21

How do you know something is slow?

The first step in making your app faster is knowing what is slow. How do you figure that out?
2023-08-18

What if you need a value that's random AND unique?

Sometimes we need random data that is ALSO unique. How can you generate that in Laravel?
2023-08-17

Harness that post-conference excitement

New features! New packages! New techniques! How can we harness that excitement when we get back to work a conference?
2023-08-16

Learn to love code review

Code review feedback might make us feel defensive, but if you approach it with the right attitude it can become something you value.
2023-08-15

Find out what's slow BEFORE you deploy to prod

The earlier you find an issue, the better! How can we improve our chances of finding slow code before it reaches production?
2023-08-14

Sometimes Eloquent can make a query slower

Eloquent improves developer efficiency, but in some cases it can make a query less efficient. Let's look at one example and how to fix it.
Don't miss out - get a tip like this in your inbox every weekday? Sign up below 👇🏼

Level up your Laravel skills!

Each 2-minute email has real-world advice you can use.