100 Laravel Quick Tips [FREE PDF]

After working with Laravel for 5 years, I've shared a lot of tips on my blog/Twitter/Youtube.Back in 2018, I've gathered 40 Laravel quick tips in an e-book, and last week I've updated it to 100 tips in total. Get it for free here: [https://laraveldaily.com/wp-content/uploads/2020/04/laravel-tips-2020-04.pdf](https://laraveldaily.com/wp-content/uploads/2020/04/laravel-tips-2020-04.pdf)

No email opt-in, no strings attached, just the e-book :)But... if you do want to get similar NEW tips every week, you can subscribe to my newsletter that comes out every Thursday: [https://laraveldaily.com/weekly-laravel-newsletter/](https://laraveldaily.com/weekly-laravel-newsletter/)

**Update**: thanks to u/MarceauKa (and others in the comments), now we have a repository Github version: [https://github.com/LaravelDaily/laravel-tips](https://github.com/LaravelDaily/laravel-tips)

9 thoughts on “100 Laravel Quick Tips [FREE PDF]”

  1. Great Job .. I think you could create a repo so the people could fork it for easy copy paste. If you have no objection, i can create it for you!!

  2. Cool work, but I have a few comments.

    Tip #95 is not really renaming the table, it’s renaming the `pivot` pseudo-relation.

    Can’t agree to #89, the plain and straightforward way seems a lot more readable.

  3. Some additions/corrections:

    Tip 2: In Laravel 7, use `$table->id()` for PKs and `$table->foreignId()` for FKs instead. Also mentioned in Tip 63.

    Tip 3: Not just `orderBy()` – the relations proxy method calls to the underlying query builder, so you can use any method that’s available on the query builder.

    Tip 11: You also have more granular control by setting the `CREATED_AT` and `UPDATED_AT` class constants, as mentioned in Tip 59. What isn’t mentioned in Tip 59: You can set them to `null` to disable them. For example, setting `const CREATED_AT = ‘creation’` and `const UPDATED_AT = null` will cause Eloquent to save the creation date in a column named `creation` (instead of the default `created_at`) and disable the `updated_at` column.

    Tip 31: Small addition: APP_URL is only used then running in the console (anything that runs through artisan, which includes things like scheduled commands and queue workers) or when sending mail using the default layout. When serving HTTP requests, the scheme and host name used in the request are used instead.

    Tip 49: I’d recommend setting `protected $namespace = ”` in your RouteServiceProvider and using single action controllers (see Tip 1), then you can simply do `$router->get(‘/foo’, \App\Http\Controllers\FooController::class)`.

    Tip 51: Use `whereNull(‘x’)` instead. Don’t use an empty string unless you’re actually trying to find empty strings.

    Tip 59: See Tip 11.

    Tip 63: See Tip 2.

    Tip 79: If you catch `QueryException`, you can also get the SQL using `$e->getSql()` and the bindings using `$e->getBindings()`.

    Tip 84: This is already mentioned in Tip 29.

    Tip 91: This is already mentioned in Tip 20.

    Tip 96: Just reuse the first relation: `return $this->comments()->where(…)`.

  4. This is great work! Like # 96 I think you can extend the query builder. Helps to remove clutter from the model file.


Leave a Comment