1
0
Fork 0
mirror of https://github.com/archtechx/laravel-tips.git synced 2025-12-12 05:14:04 +00:00

Merge pull request #19 from archtechx/week-49

Weekly thread #49
This commit is contained in:
Samuel Štancl 2021-12-10 17:13:08 +01:00 committed by GitHub
commit dc90af54b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 126 additions and 1 deletions

View file

@ -1,5 +1,5 @@
---
username: LiamHammett
name: 'Liam Hammett'
avatar: 'https://pbs.twimg.com/profile_images/1236048705297485837/oGeWeWid_normal.jpg'
avatar: 'https://pbs.twimg.com/profile_images/1436690674833891341/vOl5qtiA_normal.jpg'
---

View file

@ -0,0 +1,11 @@
---
slug: weekly-thread-2021-49
title: 'Weekly thread #49 of 2021'
tweet_id: '1469321059585331201'
author_username: archtechx
created_at: 2021-12-10T15:22:03+00:00
links: { }
---
🔥 This week's code tips for Laravel developers
🧵 A weekly thread

View file

@ -0,0 +1,14 @@
---
title: 'If you''re returning class names (as opposed to instances), you can use the class-name docblock'
tweet_id: '1469321064668753921'
thread_slug: weekly-thread-2021-49
author_username: freekmurze
images:
- 'https://pbs.twimg.com/media/FGFgPPKWYAoNJB9.jpg'
created_at: 2021-12-10T15:00:15+00:00
slug: if-youre-returning-class-names-as-opposed-to-instances-you-can-use-the-class-name-docblock
---
If youre returning a fully qualified class name, you can use the `class-name` docblock. You can specify a base class or interface between `<>`
And of course, you can also return an array of `class-name`s too 👍
#php

View file

@ -0,0 +1,14 @@
---
title: 'Keep validation rules inside models to make your code more consistent and clean'
tweet_id: '1469321060604514304'
thread_slug: weekly-thread-2021-49
author_username: archtechx
images: { }
created_at: 2021-12-10T15:00:14+00:00
slug: keep-validation-rules-inside-models-to-make-your-code-more-consistent-and-clean
---
This pattern is brilliant and can make your code much more clean and consistent
The tweet is from last year, but it's still very relevant
https://twitter.com/LiamHammett/status/1260252814158282752

View file

@ -0,0 +1,11 @@
---
title: 'This pattern is brilliant and can make your code much more clean and consistent'
tweet_id: '1468596267458588676'
thread_slug: weekly-thread-2021-49
author_username: LiamHammett
images:
- 'https://pbs.twimg.com/media/EX1RMP1X0AApuv6.jpg'
created_at: 2021-12-08T15:00:10+00:00
slug: this-pattern-is-brilliant-and-can-make-your-code-much-more-clean-and-consistent
---
🔥 I often find myself keeping validation rules in a method on the model. This lets me reuse them wherever I may need - including in controllers or form requests.

View file

@ -0,0 +1,18 @@
---
title: 'Use typehints wherever possible to improve code safety and IDE support'
tweet_id: '1469321063242731523'
thread_slug: weekly-thread-2021-49
author_username: archtechx
images:
- 'https://pbs.twimg.com/media/FGFJmbVVQAEv_oj.jpg'
created_at: 2021-12-10T15:00:14+00:00
slug: use-typehints-wherever-possible-to-improve-code-safety-and-ide-support
---
🔥 Simple typehints and annotations go a long way
Even without any docblocks, this code is perfectly understandable by both developers and IDEs
Writing code like this:
👉 Prevents bugs using type safety
👉 Makes the code self-documenting
👉 Takes only a few seconds to implement

View file

@ -0,0 +1,14 @@
---
title: 'Writing simple "page can be visited" tests is a great way to get started with testing'
tweet_id: '1469321067399303170'
thread_slug: weekly-thread-2021-49
author_username: enunomaduro
images:
- 'https://pbs.twimg.com/media/FGKWEIlXoAIpBiR.jpg'
created_at: 2021-12-10T15:00:15+00:00
slug: writing-simple-page-can-be-visited-tests-is-a-great-way-to-get-started-with-testing
---
Does your @laravelphp application have 0 tests? Here is one test you can easily add to get started. It's probably the most important test — in web projects — and it has an enormous value.
✓ Ensures your application boots. ✅
✓ Ensures the home page can be loaded. 💨

View file

@ -0,0 +1,13 @@
---
title: 'You can add a messages() method to form requests to customize their validation error messages'
tweet_id: '1469321068632444928'
thread_slug: weekly-thread-2021-49
author_username: freekmurze
images:
- 'https://pbs.twimg.com/media/FF2CRarXEAMNqZg.jpg'
- 'https://pbs.twimg.com/media/FF2CRdRXEAEpXNV.jpg'
created_at: 2021-12-10T15:00:16+00:00
slug: you-can-add-a-messages-method-to-form-requests-to-customize-their-validation-error-messages
---
❌ To customise a validation message for a request in @laravelphp , you can add a `message` function to a form request. Very handy!
#laravel #php

View file

@ -0,0 +1,13 @@
---
title: 'You can calculate multiple aggregates in a single database query'
tweet_id: '1469321061955108864'
thread_slug: weekly-thread-2021-49
author_username: tobias_petry
images:
- 'https://pbs.twimg.com/media/FF5qzyXXwAc445P.jpg'
created_at: 2021-12-10T15:00:14+00:00
slug: you-can-calculate-multiple-aggregates-in-a-single-database-query
---
⚡️ Database Tip
You don't have to execute multiple queries to calculate different aggregates. With the filter clause you can narrow the rows which should be included for the calculation. So you may need to scan the table only once, the performance impact can be massive 🔥

View file

@ -0,0 +1,17 @@
---
title: 'You can use $request->whenFilled() to execute some logic only when a specific value is part of the request data'
tweet_id: '1469321066182955010'
thread_slug: weekly-thread-2021-49
author_username: mmartin_joo
images:
- 'https://pbs.twimg.com/media/FF38VhkXsAAv0VW.png'
created_at: 2021-12-10T15:00:15+00:00
slug: you-can-use-request-whenfilled-to-execute-some-logic-only-when-a-specific-value-is-part-of-the-request-data
---
🔥Another amazing #Laravel feature!🔥
We often write if statements to check if a value is present on a request or not.
You can simplify it with the whenFilled() helper.
👋If you find this useful, consider clicking the button that says Retweet. It's a very cool button!