100 Laravel Quick Tips

by Povilas Korop

DescriptionTable of ContentsDetailsHashtagsReport an issue

Book Description

Laravel is full of hidden gems, undocumented or less-known features, functions parameters and "hacks". While finding them in work of my team, I decided to compile them into an ebook.

This open book is licensed under a Open Publication License (OPL). You can download 100 Laravel Quick Tips ebook for free in PDF format (0.3 MB).

Table of Contents

Tip 1
Single Action Controllers
Tip 2
Unsigned Integer
Tip 3
OrderBy on Eloquent relationships
Tip 4
Order of Migrations
Tip 5
Raw DB Queries: havingRaw()
Tip 6
$loop variable in foreach
Tip 7
Eloquent where date methods
Tip 8
Route group within a group
Tip 9
Increments and decrements
Tip 10
Does view file exist?
Tip 11
No timestamp columns
Tip 12
Migration fields with timezones
Tip 13
Eloquent has() deeper
Tip 14
Database migrations column types
Tip 15
Artisan command help
Tip 16
Default Timestamp
Tip 17
Set logged in user with Observers
Tip 18
Soft-deletes: multiple restore
Tip 19
Has Many. How many exactly?
Tip 20
Image validation
Tip 21
Wildcard subdomains
Tip 22
Exact Laravel version
Tip 23
Testing email into laravel.log
Tip 24
Error code Blade pages
Tip 25
Factory callbacks
Tip 26
Artisan command parameters
Tip 27
Preview Mailables
Tip 28
Route::view() - Don't create Controllers
Tip 29
Blade @auth
Tip 30
Model all: columns
Tip 31
Localhost in .env
Tip 32
What's behind the routes?
Tip 33
To Fail or not to Fail
Tip 34
Column name change
Tip 35
Logging with parameters
Tip 36
Default Model
Tip 37
Use hasMany to create Many
Tip 38
More convenient DD
Tip 39
Map query results
Tip 40
Custom validation error messages
Tip 41
When (NOT) to run "composer update"
Tip 42
Two-level $loop variable in Blade
Tip 43
Route Model Binding: You can define a key
Tip 44
Redirect to Specific Controller Method
Tip 45
Did you know about Auth::once()?
Tip 46
Eager Loading with Exact Columns
Tip 47
Validate dates with "now" or "yesterday" words
Tip 48
Touch parent updated_at easily
Tip 49
Quickly Navigate from Routes file to Controller
Tip 50
Always Check if Relationship Exists
Tip 51
Don't Filter by NULL in Collections
Tip 52
Default Email Subject in Laravel Notifications
Tip 53
Composer: Check for Newer Versions
Tip 54
Route Fallback - When no Other Route is Matched
Tip 55
Create Your Own Blade Directive
Tip 56
Use withCount() to Calculate Child Relationships Records
Tip 57
Use groupBy on Collections with Custom Callback Function
Tip 58
Blade Directives: IncludeIf, IncludeWhen, IncludeFirst
Tip 59
Change Default Timestamp Fields
Tip 60
Quick Order by created_at
Tip 61
Generate Images with Seeds/Factories
Tip 62
Eloquent: Update Parent in One Line
Tip 63
Eloquent: Laravel 7+ Foreign Keys
Tip 64
Multiple Collection Methods in a Row
Tip 65
More Events on User Registration
Tip 66
Extra Filter Query on Relationships
Tip 67
Send Notifications to Anyone
Tip 68
Sub-selects in Laravel Way
Tip 69
API Resources: With or Without "data"?
Tip 70
API Return "Everything went ok"
Tip 71
Automatic Column Value When Creating Records
Tip 72
DB Raw Query Calculations Run Faster
Tip 73
More than One Scope
Tip 74
Hide Some Columns
Tip 75
Combine Two "whereHas"
Tip 76
Auto-Capitalize Translations
Tip 77
Validation Rule with Some Conditions
Tip 78
Check if Relationship Method Exists
Tip 79
Exact DB Error
Tip 80
Route Parameters Validation with RegExp
Tip 81
Rate Limiting: Global and for Guests/Users
Tip 82
Add Parameters to Routes
Tip 83
Check Multiple Permissions at Once
Tip 84
Check Auth Quicker
Tip 85
No Need to Convert Carbon
Tip 86
Soft-Deletes with Query Builder
Tip 87
Grouping by First Letter
Tip 88
Load Relationships Always, but Dynamically
Tip 89
Instead of belongsTo, use hasMany
Tip 90
Change Default Validation Messages
Tip 91
Validate Images Dimensions
Tip 92
Carbon with Only Hours/Minutes
Tip 93
Good Old SQL Query
Tip 94
Prepare for Validation
Tip 95
Rename Pivot Table
Tip 96
Similar Relationship but With Condition
Tip 97
Never Update the Column
Tip 98
Maintenance Mode
Tip 99
Find Many
Tip 100
Stop on First Validation Error

Book Details

Subject
Computer Science
Publisher
Self-publishing
Published
2020
Pages
41
Edition
1
Language
English
PDF Size
0.3 MB
License
Open Publication License

Related Books

D3 Tips and Tricks v3.x
D3 Tips and Tricks is a book written to help those who may be unfamiliar with JavaScript or web page creation get started turning information into visualization. Data is the new medium of choice for telling a story or presenting compelling information on the Internet and d3.js is an extraordinary framework for presentation of data on a web page....
Primary Angioplasty
This quick-reference handbook offers a concise and practical review of key aspects of the treatment of ST-segment elevation myocardial infarction (STEMI) in the era of primary percutaneous coronary intervention (PPCI). In the context of STEMI, PPCI is the preferred mode of emergency revascularization. Access to PPCI is rapidly increasing and is now...
Achieving the Paris Climate Agreement Goals
This book presents detailed pathways to achieve 100% renewable energy by 2050, globally and across ten geographical regions. Based on state-of-the-art scenario modelling, it provides the vital missing link between renewable energy targets and the measures needed to achieve them. Bringing together the latest research in climate science, renewable en...
50 Ways to Avoid Find and Fix ASP.NET Performance Issues
Read the tips and tricks that top developers from the .NET and SQL Server communities use to boost code and query performance in their applications. 50 tips from the .NET and SQL Server communities for boosting performance in your .NET application; Learn the secrets of your fellow developers and read advice from MVPs and other experts; Covers pe...
Quick Start Guide to VHDL
This book provides a starter's guide to VHDL. This book can be used in conjunction with a one-semester course in Digital Systems Design or on its own for designers who only need an introduction to the language. This book is designed to provide a bottoms-up approach to learning the VHDL language. This design supports a course in which foundational k...
Laravel Collections Unraveled
In "Laravel Collections Unraveled" we are going to see just what is so amazing about this class by digging down under the hood to understand the full range of functions availalble, and create practical examples of each of them that we can use right away. In the process, we're going to perhaps improve our basic PHP skills a bit by getting ...