laravelmastery
SnippetsArticlesSeriesNews

Snippets

Paste-ready Laravel you can drop into a service provider, a job, or a test. Each one is short enough to read in a minute, and written for the code you already ship.

All EloquentQueriesQueuesTestingHTTPArtisanFactories

9 snippets

12 Next

Refuse attributes a model will throw away

Catch a typo in a fillable list during development, before the column quietly stays null.

Eloquent · Guard rail

Read

Name the interesting states

A factory state keeps a void invoice readable in the test, instead of a pile of overrides.

Testing · Factories

Read

Stop the same job running twice

WithoutOverlapping holds a lock for one model so a double dispatch waits its turn.

Queues · Jobs

Read

Catch N+1 queries before your users do

Turn lazy loading into an exception outside production, so missing eager loads fail loudly in development and tests.

Eloquent · Snippet of the week

Read

Listen to one request’s queries

Drop this in a local route while you hunt an unexpected query.

Eloquent · Debugging

Read

Scope a child route to its parent

A line URL only resolves when that line belongs to the invoice.

HTTP · Routes

Read

Get the Friday email

One snippet and the week’s Laravel news, in your inbox every Friday morning. Unsubscribe whenever you like.

laravelmastery

Practical Laravel learning for working developers, made in the UK.

Learn

  • Snippets
  • Articles
  • Series

Stay current

  • News
  • Friday email
  • RSS feed

Company

  • About
  • Privacy
  • Terms
© 2026 Laravel Mastery. Independent and not affiliated with Laravel Holdings Inc.Designed and built by Half Shell Studios

We remember the videos you watch, where you left off, and which series lessons you mark as read, against this connection’s address. Nothing is stored until you agree.