πŸ”₯ 1 RT = 1 tip

A thread of misc tips, originally one tip per one retweet.

This one is less obscure

26

πŸ”₯ This one is less obscure

This one is less obscure

The $loop variable.

It greatly complements Tailwind-styled tables.

Striped tables done easily πŸŽ‰

Laravel migrations have a very nice syntax for foreign keys

21

πŸ”₯ Laravel migrations have a very nice syntax for foreign keys

I didn't know about this for so long.

Instead of: $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users');

You do: $table->foreignId('user_id')->constrained();

Comparing changes on 'saving' using:

17

πŸ”₯ Comparing changes on 'saving' using:

Comparing changes on 'saving' using:

$model->getOriginal()

in Eloquent event listeners can be very useful.

One such use case is checking whether an order is locked. If it is, the only write action we permit is unlocking it. Only then can changes be made.

Laravel Telescope is great for so many things

13

πŸ”₯ Laravel Telescope is great for so many things

Laravel Telescope is great for so many things

One of them is examining sent emails βœ‰οΈ

You usually don't need a service like Mailtrap. Just use the log mail driver and install Telescope.

(image stolen from the internet)

Relevant for people building packages πŸ“¦

11

πŸ”₯ Relevant for people building packages πŸ“¦

Relevant for people building packages πŸ“¦

It's IMO better to use static properties and have "self-contained" behavior & configuration. Than to have a billion config keys. Especially when building large packages.

Makes the package more extensible, by consisting of atomic parts

People underutilize the exception handler

5

πŸ”₯ People underutilize the exception handler

People underutilize the exception handler

You can tell the app what response to return when a specific exception is encountered.

This is the simplest example. There's many more use cases.

We're writing a book, you can get it for free here.