Laravel Pro Tips
#eloquent #relationships
π₯ #Laravel Tip: Eloquent offers many undocumented methods that can help to make your code easier to read. For example, the whereBelongsTo method simplifies finding resources that belong to a model instance.
Matt Kingshott
#migrations
#Laravel Migration Tip π₯ You can use the `from` method to set the starting value of an auto-incrementing field.
Gurmandeep Singh
#validation #closure
#Laravel Validation Tip π₯ You can use a closure instead of a rule object if you only need a custom rule once throughout your application. The closure receives the attribute's name, the attribute's value, and a `fail` callback that should be called if validation fails.
#validation #error #ux
π₯ #Laravel Tip: Using custom error messages for failed request validation is straight out of the docs, but itβs amazing how rarely it gets used. Make your apps better and improve their UX by giving users more guidance in solving validation errors.
#macros #query builder
π₯ #Laravel Tip: Macros provide a way to add missing functionality to many parts of the framework, such as the query builder. These macros can be "user-facing", but they don't have to be. Sometimes they can be used just to make your tests simpler (or to aid in debugging).
#http #macros
π‘ You can define HTTP macro to configure common request paths and headers when interacting with services throughout your application. #laravel #laravelphp #laraveltips #laraveltricks #laravelupdates #laravelfeatures
Laravel Updates | Tips and Tricks
#eloquent #debugging
TIL, in Laravel you can display debug information about the current query with dump() and dd() π€ This allows you to see the underlying query and bindings.
Daniel Eckermann
#validation #requests
π₯ #Laravel Tip: Sometimes you want to validate part of the request's data, but you don't actually need the data (and must make a point of filtering it out) e.g. a bool confirming the user accepts terms and conditions. In these situations, use the 'exclude' validation rule.
#database
π₯ #Laravel Tip: Instructing the database to delete a huge number of records is likely to make it fall over (esp. when using cascade deletion). However, you can avoid this by staggering the process into batches and adding pauses to allow the database time to catch up.