{ Laravel snippets }

Liam Hammett

Liam Hammett @LiamHammett

🔥 You don't need a closing tag when using the @​php directive in @laravelphp Blade, you can put some logic on a single line. It's especially nice to use it to do things like setting default values in a partial with the null-coalesce-assign operator. https://t.co/raQZBfPyxm

💡 in Laravel you can do things as the framework is terminating (after request has been processed!) You can do this in a middleware, using App::terminating with callback or natively with PHP using register_shutdown_function https://t.co/Z6tzN8jdkd

Liam Hammett

Liam Hammett @LiamHammett

🔥 With Laravel Mix, if you're building Sass files, you can pass a list of PostCSS plugins as the fourth parameter that will only apply to the given file. This is useful if you want one process to handle multiple things as usually the postCss method will apply to all CSS files https://t.co/B67M4kWOX4

Jason McCreary

Jason McCreary @gonedark

Piggybacking off the last 🔥 tip, most Blade templates simply use the `if` directive. However, there are so many more Blade directives available. These are not only more expressive, but often streamline the code. Here's a side-by-side comparison: https://t.co/Z2Edmf8kDO

Michael Dyrynda

Michael Dyrynda @michaeldyrynda

🧐 The @laravelphp docs are a fantastic resource to read over from time to time, given how often new features are added to the framework. ❓Did you know you can add a public shouldQueue method on your job to determine if the job actually *needs* to be queued? https://t.co/9E1uIrmugK

🔥 If you're allowing a ?perPage= query param to be specified for your pagination results, LIMIT it! Particularly if you have a huge number of potential records. You can do this easily with the native min() PHP function. https://t.co/aNW7K09Zdt

Liam Hammett

Liam Hammett @LiamHammett

🔥 Sometimes, when using factories to seed random data, I might use a little random check to use an existing model for some relationships so not everything ends up creating new models for its own relations. It helps seeded data feel a lot more realistic to use. https://t.co/4GboYEfmcM

Tim MacDonald

Tim MacDonald @timacdonald87

🍭 You can utilise the Illuminate\Support Str + Arr classes in views without importing them No need to reach for a fully qualified name or the str_ / arr_ helpers They are defined as an alias in config/app.php which makes them available in the root namespace They just work™️ https://t.co/gUcutOebUL