diff --git a/content/authors/doekenorg.md b/content/authors/doekenorg.md new file mode 100644 index 0000000..5445073 --- /dev/null +++ b/content/authors/doekenorg.md @@ -0,0 +1,5 @@ +--- +username: doekenorg +name: 'Doeke Norg' +avatar: 'https://pbs.twimg.com/profile_images/641960403287834624/OLaPNjGt_normal.jpg' +--- diff --git a/content/authors/mattkingshott.md b/content/authors/mattkingshott.md new file mode 100644 index 0000000..e3cc42c --- /dev/null +++ b/content/authors/mattkingshott.md @@ -0,0 +1,5 @@ +--- +username: mattkingshott +name: 'Matt Kingshott 🏝' +avatar: 'https://pbs.twimg.com/profile_images/1444979706571415564/toC9_E-T_normal.jpg' +--- diff --git a/content/authors/mmartin_joo.md b/content/authors/mmartin_joo.md new file mode 100644 index 0000000..c8b792e --- /dev/null +++ b/content/authors/mmartin_joo.md @@ -0,0 +1,5 @@ +--- +username: mmartin_joo +name: 'Martin Joo' +avatar: 'https://pbs.twimg.com/profile_images/1456657123639795724/5diaoilq_normal.jpg' +--- diff --git a/content/authors/xiCO2k.md b/content/authors/xiCO2k.md new file mode 100644 index 0000000..e7a69c5 --- /dev/null +++ b/content/authors/xiCO2k.md @@ -0,0 +1,5 @@ +--- +username: xiCO2k +name: 'Francisco Madeira' +avatar: 'https://pbs.twimg.com/profile_images/1238877427306242055/aspixMYU_normal.jpg' +--- diff --git a/content/threads/weekly-thread-2021-46.md b/content/threads/weekly-thread-2021-46.md new file mode 100644 index 0000000..110bfbb --- /dev/null +++ b/content/threads/weekly-thread-2021-46.md @@ -0,0 +1,11 @@ +--- +slug: weekly-thread-2021-46 +title: 'Weekly thread #46 of 2021' +tweet_id: '1461703825039892486' +author_username: archtechx +created_at: 2021-11-19T15:07:06+00:00 +links: { } +--- +πŸ”₯ This week's code tips for Laravel developers + +A weekly thread 🧡 \ No newline at end of file diff --git a/content/tips/create-renderable-exceptions.md b/content/tips/create-renderable-exceptions.md new file mode 100644 index 0000000..0764ebd --- /dev/null +++ b/content/tips/create-renderable-exceptions.md @@ -0,0 +1,13 @@ +--- +title: 'Create renderable exceptions' +tweet_id: '1461703839388626946' +thread_slug: weekly-thread-2021-46 +author_username: Philo01 +images: + - 'https://pbs.twimg.com/media/FEewo1NXMAgaMbb.jpg' +created_at: 2021-11-19T14:32:07+00:00 +slug: create-renderable-exceptions +--- +Laravel Tip: You can customize how your exceptions are rendered by adding a 'render' method to your exception. + +For example, this allows you to return JSON instead of a Blade view when the request expects JSON. \ No newline at end of file diff --git a/content/tips/including-a-unique-value-like-now-or-strrandom-in-the-blade-template-of-a-livewire-component-is-a-great-way-to-check-if-that-part-of-the-dom-is-getting-re-rendered.md b/content/tips/including-a-unique-value-like-now-or-strrandom-in-the-blade-template-of-a-livewire-component-is-a-great-way-to-check-if-that-part-of-the-dom-is-getting-re-rendered.md new file mode 100644 index 0000000..f242daf --- /dev/null +++ b/content/tips/including-a-unique-value-like-now-or-strrandom-in-the-blade-template-of-a-livewire-component-is-a-great-way-to-check-if-that-part-of-the-dom-is-getting-re-rendered.md @@ -0,0 +1,13 @@ +--- +title: 'Including a unique value, like now() or Str::random(), in the Blade template of a Livewire component is a great way to check if that part of the DOM is getting re-rendered' +tweet_id: '1461703833617272840' +thread_slug: weekly-thread-2021-46 +author_username: alexjgarrett +images: + - 'https://pbs.twimg.com/media/FEWOM0UXsAQyJ89.jpg' +created_at: 2021-11-19T14:32:05+00:00 +slug: including-a-unique-value-like-now-or-strrandom-in-the-blade-template-of-a-livewire-component-is-a-great-way-to-check-if-that-part-of-the-dom-is-getting-re-rendered +--- +A quick and easy way to check if @LaravelLivewire components are re-rendering when you don't want/need them to. + +Add now() or now()->timestamp to your component template. The time value will increment if there's a re-render side effect! \ No newline at end of file diff --git a/content/tips/use-appends-to-include-properties-in-the-array-representation-of-your-model.md b/content/tips/use-appends-to-include-properties-in-the-array-representation-of-your-model.md new file mode 100644 index 0000000..2c8bca7 --- /dev/null +++ b/content/tips/use-appends-to-include-properties-in-the-array-representation-of-your-model.md @@ -0,0 +1,11 @@ +--- +title: 'Use $appends to include properties in the array representation of your model' +tweet_id: '1461703842026770438' +thread_slug: weekly-thread-2021-46 +author_username: xiCO2k +images: + - 'https://pbs.twimg.com/media/FEO04rDXsAAQx6i.jpg' +created_at: 2021-11-19T14:32:07+00:00 +slug: use-appends-to-include-properties-in-the-array-representation-of-your-model +--- +Had to revisit a #Laravel project from 3 years ago, and found out I did append a mutator in the toArray method πŸ˜‚, there is no need for that, we can use the "$appends" and it does the same job βœ… \ No newline at end of file diff --git a/content/tips/use-explicit-null-handling-in-your-db-queries-when-filtering-for-rows-with-empty-value-in-a-nullable-column.md b/content/tips/use-explicit-null-handling-in-your-db-queries-when-filtering-for-rows-with-empty-value-in-a-nullable-column.md new file mode 100644 index 0000000..0f3ff52 --- /dev/null +++ b/content/tips/use-explicit-null-handling-in-your-db-queries-when-filtering-for-rows-with-empty-value-in-a-nullable-column.md @@ -0,0 +1,13 @@ +--- +title: 'Use explicit null handling in your DB queries when filtering for rows with empty value in a nullable column' +tweet_id: '1461703840755978242' +thread_slug: weekly-thread-2021-46 +author_username: tobias_petry +images: + - 'https://pbs.twimg.com/media/FEEibLTXEAMaNrl.jpg' +created_at: 2021-11-19T14:32:07+00:00 +slug: use-explicit-null-handling-in-your-db-queries-when-filtering-for-rows-with-empty-value-in-a-nullable-column +--- +⚑️ Database Tip + +Comparing anything to a null value is always null too (meaning false). Simple operations like searching for rows with an unequal value will be more complicated. But null safe operators are making those queries dead simple again. \ No newline at end of file diff --git a/content/tips/use-the-loop-variable-in-blade-foreach-loops-to-access-metadata-about-the-loop.md b/content/tips/use-the-loop-variable-in-blade-foreach-loops-to-access-metadata-about-the-loop.md new file mode 100644 index 0000000..5a8b242 --- /dev/null +++ b/content/tips/use-the-loop-variable-in-blade-foreach-loops-to-access-metadata-about-the-loop.md @@ -0,0 +1,13 @@ +--- +title: 'Use the $loop variable in Blade foreach loops to access metadata about the loop' +tweet_id: '1461703837916405761' +thread_slug: weekly-thread-2021-46 +author_username: alexjgarrett +images: + - 'https://pbs.twimg.com/media/FEemqXrXIAgeMTB.jpg' +created_at: 2021-11-19T14:32:06+00:00 +slug: use-the-loop-variable-in-blade-foreach-loops-to-access-metadata-about-the-loop +--- +A handy $loop object is available in Laravel Blade foreach loops. Super useful for controlling output based on the loop position ➰ + +Source dive for reference: https://github.com/laravel/framework/blob/8.x/src/Illuminate/View/Concerns/ManagesLoops.php \ No newline at end of file diff --git a/content/tips/use-the-nullordelete-method-in-your-relationship-column-definitions-to-clear-their-value-when-the-parent-record-gets-deleted.md b/content/tips/use-the-nullordelete-method-in-your-relationship-column-definitions-to-clear-their-value-when-the-parent-record-gets-deleted.md new file mode 100644 index 0000000..7e0280c --- /dev/null +++ b/content/tips/use-the-nullordelete-method-in-your-relationship-column-definitions-to-clear-their-value-when-the-parent-record-gets-deleted.md @@ -0,0 +1,15 @@ +--- +title: 'Use the nullOrDelete() method in your relationship column definitions to clear their value when the parent record gets deleted' +tweet_id: '1461703828953198601' +thread_slug: weekly-thread-2021-46 +author_username: mmartin_joo +images: + - 'https://pbs.twimg.com/media/FEQ4DcdXsAcePgo.jpg' +created_at: 2021-11-19T14:32:04+00:00 +slug: use-the-nullordelete-method-in-your-relationship-column-definitions-to-clear-their-value-when-the-parent-record-gets-deleted +--- +πŸ”₯#Laravel Migration tipπŸ”₯ + +Do you have a relationship that is nullable? + +You can use the nullOnDelete() function. It achieves ON DELETE SET NULL behavior: \ No newline at end of file diff --git a/content/tips/use-the-quietly-methods-to-create-models-without-firing-events-using-your-factories.md b/content/tips/use-the-quietly-methods-to-create-models-without-firing-events-using-your-factories.md new file mode 100644 index 0000000..c30e0f0 --- /dev/null +++ b/content/tips/use-the-quietly-methods-to-create-models-without-firing-events-using-your-factories.md @@ -0,0 +1,17 @@ +--- +title: 'Use the *quietly() methods to create models without firing events using your factories' +tweet_id: '1461703827355168772' +thread_slug: weekly-thread-2021-46 +author_username: pascalbaljet +images: + - 'https://pbs.twimg.com/media/FEEXi0zXoAAtd7b.jpg' +created_at: 2021-11-19T14:32:04+00:00 +slug: use-the-quietly-methods-to-create-models-without-firing-events-using-your-factories +--- +πŸ“ Here's part 2 of the new Database and Eloquent ORM features in @laravelphp 8.x since the release in September 2020. + +One of my favorites is the ability in Model Factories to create models without dispatching any events πŸ”₯ + +Blog post: https://protone.media/en/blog/database-and-eloquent-orm-new-features-and-improvements-since-the-original-laravel-8-release-22 + +#Laravel #PHP \ No newline at end of file diff --git a/content/tips/use-the-something-at-convention-instead-of-is-something-in-your-table-definitions.md b/content/tips/use-the-something-at-convention-instead-of-is-something-in-your-table-definitions.md new file mode 100644 index 0000000..7931b53 --- /dev/null +++ b/content/tips/use-the-something-at-convention-instead-of-is-something-in-your-table-definitions.md @@ -0,0 +1,11 @@ +--- +title: 'Use the something_at convention instead of is_something in your table definitions' +tweet_id: '1461703830240776197' +thread_slug: weekly-thread-2021-46 +author_username: alexjgarrett +images: + - 'https://pbs.twimg.com/media/FEAG6YUXEBMceDT.jpg' +created_at: 2021-11-19T14:32:04+00:00 +slug: use-the-something-at-convention-instead-of-is-something-in-your-table-definitions +--- +Using the 'something_at' convention instead of just a boolean in Laravel models gives you visibility into when a flag was changed – like when a product went live. \ No newline at end of file diff --git a/content/tips/you-can-use-schema-methods-eg-table-or-create-outside-of-migrations.md b/content/tips/you-can-use-schema-methods-eg-table-or-create-outside-of-migrations.md new file mode 100644 index 0000000..8f6c09c --- /dev/null +++ b/content/tips/you-can-use-schema-methods-eg-table-or-create-outside-of-migrations.md @@ -0,0 +1,13 @@ +--- +title: 'You can use Schema methods β€” e.g. table() or create() β€” outside of migrations' +tweet_id: '1461703835215228932' +thread_slug: weekly-thread-2021-46 +author_username: aarondfrancis +images: + - 'https://pbs.twimg.com/media/FEfnHQxWQAwIbVq.jpg' +created_at: 2021-11-19T14:32:06+00:00 +slug: you-can-use-schema-methods-eg-table-or-create-outside-of-migrations +--- +I don't do it very often, but you can use Laravel's Schema builder anywhere you want, not just in migrations! + +If you ever need to make a temp table to help you mass process data more quickly, it's a great solution. \ No newline at end of file diff --git a/content/tips/you-can-use-the-data-get-method-to-safely-access-a-nested-array-value.md b/content/tips/you-can-use-the-data-get-method-to-safely-access-a-nested-array-value.md new file mode 100644 index 0000000..d593957 --- /dev/null +++ b/content/tips/you-can-use-the-data-get-method-to-safely-access-a-nested-array-value.md @@ -0,0 +1,11 @@ +--- +title: 'You can use the data_get() method to safely access a nested array value' +tweet_id: '1461703836553265154' +thread_slug: weekly-thread-2021-46 +author_username: mattkingshott +images: + - 'https://pbs.twimg.com/media/FEZJDDbWYAE2fiL.jpg' +created_at: 2021-11-19T14:32:06+00:00 +slug: you-can-use-the-data-get-method-to-safely-access-a-nested-array-value +--- +πŸ’‘#Laravel Tip: Dealing with deeply-nested arrays can result in missing key / value exceptions. Fortunately, Laravel's data_get() helper makes this easy to avoid. It also supports deeply-nested objects. \ No newline at end of file diff --git a/content/tips/you-can-use-the-formanother-form-attribute-on-buttons-to-submit-a-different-form.md b/content/tips/you-can-use-the-formanother-form-attribute-on-buttons-to-submit-a-different-form.md new file mode 100644 index 0000000..b8ba940 --- /dev/null +++ b/content/tips/you-can-use-the-formanother-form-attribute-on-buttons-to-submit-a-different-form.md @@ -0,0 +1,13 @@ +--- +title: 'You can use the form="another-form" attribute on buttons to submit a different form' +tweet_id: '1461703831960440837' +thread_slug: weekly-thread-2021-46 +author_username: doekenorg +images: + - 'https://pbs.twimg.com/media/FEZQ4UOXEAo2mlv.jpg' +created_at: 2021-11-19T14:32:05+00:00 +slug: you-can-use-the-formanother-form-attribute-on-buttons-to-submit-a-different-form +--- +πŸ”₯ I sometimes forget you can use `form="form-name"` on input types to hook fields inside one form to another. This makes it as if those fields were inside that <form>-tag. + +This is super useful if the fields are rendered in the wrong form, but UI wise it makes sense. \ No newline at end of file diff --git a/content/tips/you-can-validate-values-for-enum-database-columns-using-the-new-enum-validation-rule.md b/content/tips/you-can-validate-values-for-enum-database-columns-using-the-new-enum-validation-rule.md new file mode 100644 index 0000000..9d42a7d --- /dev/null +++ b/content/tips/you-can-validate-values-for-enum-database-columns-using-the-new-enum-validation-rule.md @@ -0,0 +1,15 @@ +--- +title: 'You can validate values for enum database columns using the new Enum validation rule' +tweet_id: '1461703826033897473' +thread_slug: weekly-thread-2021-46 +author_username: sky_0xs +images: + - 'https://pbs.twimg.com/media/FEBiZ_-WQAQv1fY.jpg' +created_at: 2021-11-19T14:32:03+00:00 +slug: you-can-validate-values-for-enum-database-columns-using-the-new-enum-validation-rule +--- +#Laravel Updates: + +In Laravel `8.7` you can now validate `enum` columns! + +An Example: \ No newline at end of file