mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 05:14:04 +00:00
Weekly thread #43
This commit is contained in:
parent
d9cbb484cd
commit
832e3173f5
12 changed files with 112 additions and 0 deletions
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
title: 'Create traits for relationships you commonly use in your models to make your codebase cleaner, simpler, and more consistent ✨'
|
||||
tweet_id: '1454133823210459140'
|
||||
thread_slug: weekly-thread-2021-43
|
||||
author_username: jordankdalton
|
||||
images:
|
||||
- 'https://pbs.twimg.com/media/FCZiei8WYAA_mZQ.jpg'
|
||||
- 'https://pbs.twimg.com/media/FCZiei7XIAEgVSm.jpg'
|
||||
created_at: 2021-10-29T17:11:34+00:00
|
||||
slug: create-traits-for-relationships-you-commonly-use-in-your-models-to-make-your-codebase-cleaner-simpler-and-more-consistent
|
||||
---
|
||||
Laravel Tip: Abstract relations you commonly use to a trait. It’s a DRY approach that keeps your models thin.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
title: 'Implement the __toString() method in a class to specify custom logic for converting its instances to strings'
|
||||
tweet_id: '1454133805745385473'
|
||||
thread_slug: weekly-thread-2021-43
|
||||
author_username: enunomaduro
|
||||
images:
|
||||
- 'https://pbs.twimg.com/media/FCx22U5WQAYOWi4.jpg'
|
||||
created_at: 2021-10-29T17:11:30+00:00
|
||||
slug: implement-the-tostring-method-in-a-class-to-specify-custom-logic-for-converting-its-instances-to-strings
|
||||
---
|
||||
PHP reminder: you can use the method "__toString()" to specify the string representation of an object. ✅
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
title: 'Use constructor property promotion to define class properties directly on the constructor'
|
||||
tweet_id: '1454133812863152128'
|
||||
thread_slug: weekly-thread-2021-43
|
||||
author_username: enunomaduro
|
||||
images:
|
||||
- 'https://pbs.twimg.com/media/FCdTrpMX0AAid3y.jpg'
|
||||
created_at: 2021-10-29T17:11:32+00:00
|
||||
slug: use-constructor-property-promotion-to-define-class-properties-directly-on-the-constructor
|
||||
---
|
||||
PHP reminder: you can define your class properties directly on the constructor. ✅
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
title: 'Use declare(strict_types=1) to enable strict mode for type checking'
|
||||
tweet_id: '1454133808786202627'
|
||||
thread_slug: weekly-thread-2021-43
|
||||
author_username: enunomaduro
|
||||
images:
|
||||
- 'https://pbs.twimg.com/media/FCiPA0kWUAUoban.jpg'
|
||||
created_at: 2021-10-29T17:11:31+00:00
|
||||
slug: use-declarestrict-types1-to-enable-strict-mode-for-type-checking
|
||||
---
|
||||
PHP reminder: The "declare(strict_types = 1);" directive enables strict mode. In strict mode, only a variable of exact type of the “type declaration” will be accepted, or a "TypeError" will be thrown. ✅
|
||||
13
content/tips/use-not-to-reverse-an-assertion-in-pestphp.md
Normal file
13
content/tips/use-not-to-reverse-an-assertion-in-pestphp.md
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
title: 'Use ->not to reverse an assertion in @pestphp '
|
||||
tweet_id: '1454133816990240773'
|
||||
thread_slug: weekly-thread-2021-43
|
||||
author_username: enunomaduro
|
||||
images:
|
||||
- 'https://pbs.twimg.com/media/FCtnhAvXEAco-Kc.jpg'
|
||||
created_at: 2021-10-29T17:11:33+00:00
|
||||
slug: use-not-to-reverse-an-assertion-in-pestphp
|
||||
---
|
||||
Pest reminder: if you know how to test something, "not()" lets you test its opposite. ✅
|
||||
|
||||
https://pestphp.com/docs/expectations#expect-not
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
title: 'You can check if a string contains JSON by decoding it, encoding it again, and comparing the value with the original'
|
||||
tweet_id: '1454133800888410119'
|
||||
thread_slug: weekly-thread-2021-43
|
||||
author_username: freekmurze
|
||||
images:
|
||||
- 'https://pbs.twimg.com/media/FC4Bs0lXEA4WV-P.jpg'
|
||||
created_at: 2021-10-29T17:11:29+00:00
|
||||
slug: you-can-check-if-a-string-contains-json-by-decoding-it-encoding-it-again-and-comparing-the-value-with-the-original
|
||||
---
|
||||
🔥 A way to check if a string contains valid JSON: just decode it, encode it again, and check if it matches the original value
|
||||
#php
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
title: 'You can make PHP throw an exception when decoding JSON if the value isn''t valid JSON'
|
||||
tweet_id: '1454133803056775178'
|
||||
thread_slug: weekly-thread-2021-43
|
||||
author_username: SteveTheBauman
|
||||
images:
|
||||
- 'https://pbs.twimg.com/media/FCuqk2zWQAsk08o.jpg'
|
||||
created_at: 2021-10-29T17:11:29+00:00
|
||||
slug: you-can-make-php-throw-an-exception-when-decoding-json-if-the-value-isnt-valid-json
|
||||
---
|
||||
Had no idea you could have PHP throw a built-in exception when decoding JSON -- I've always done this manually until today 😭
|
||||
Loading…
Add table
Add a link
Reference in a new issue