From b451d149531c1423564281b9b50722740c87d40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sun, 20 Mar 2022 20:41:25 +0100 Subject: [PATCH] Week 11/2022 --- content/authors/aarondfrancis.md | 2 +- content/authors/djgeisi.md | 5 +++++ content/threads/weekly-thread-2022-11.md | 11 +++++++++++ .../php-traits-can-contain-abstract-methods.md | 15 +++++++++++++++ ...efine-casts-for-specific-eloquent-queries.md | 13 +++++++++++++ ...o-blade-views-using-the-withfoobar-syntax.md | 11 +++++++++++ ...cblocks-in-blade-files-to-add-ide-support.md | 15 +++++++++++++++ ...ad-to-interact-directly-with-file-streams.md | 17 +++++++++++++++++ content/tips/you-can-use-partial-queue-fakes.md | 12 ++++++++++++ ...sses-no-need-to-query-the-instances-first.md | 11 +++++++++++ .../you-can-use-this-gtmock-in-pest-tests.md | 11 +++++++++++ ...u-can-validate-data-at-the-database-level.md | 13 +++++++++++++ 12 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 content/authors/djgeisi.md create mode 100644 content/threads/weekly-thread-2022-11.md create mode 100644 content/tips/php-traits-can-contain-abstract-methods.md create mode 100644 content/tips/you-can-define-casts-for-specific-eloquent-queries.md create mode 100644 content/tips/you-can-pass-variables-to-blade-views-using-the-withfoobar-syntax.md create mode 100644 content/tips/you-can-use-docblocks-in-blade-files-to-add-ide-support.md create mode 100644 content/tips/you-can-use-native-php-functions-like-fopen-and-fread-to-interact-directly-with-file-streams.md create mode 100644 content/tips/you-can-use-partial-queue-fakes.md create mode 100644 content/tips/you-can-use-pluck-directly-on-eloquent-classes-no-need-to-query-the-instances-first.md create mode 100644 content/tips/you-can-use-this-gtmock-in-pest-tests.md create mode 100644 content/tips/you-can-validate-data-at-the-database-level.md diff --git a/content/authors/aarondfrancis.md b/content/authors/aarondfrancis.md index db4fab4..6c5b73c 100644 --- a/content/authors/aarondfrancis.md +++ b/content/authors/aarondfrancis.md @@ -1,5 +1,5 @@ --- username: aarondfrancis -avatar: 'https://pbs.twimg.com/profile_images/1492165477161914369/bXZG72Li_normal.jpg' +avatar: 'https://pbs.twimg.com/profile_images/1503487031330197518/J4i7ofgt_normal.jpg' name: 'Aaron Francis' --- diff --git a/content/authors/djgeisi.md b/content/authors/djgeisi.md new file mode 100644 index 0000000..b5e1c17 --- /dev/null +++ b/content/authors/djgeisi.md @@ -0,0 +1,5 @@ +--- +username: djgeisi +name: 'Tim Geisendoerfer' +avatar: 'https://pbs.twimg.com/profile_images/1417203113551925251/YtYwDdMt_normal.jpg' +--- diff --git a/content/threads/weekly-thread-2022-11.md b/content/threads/weekly-thread-2022-11.md new file mode 100644 index 0000000..b253ff9 --- /dev/null +++ b/content/threads/weekly-thread-2022-11.md @@ -0,0 +1,11 @@ +--- +slug: weekly-thread-2022-11 +title: 'Weekly thread #11 of 2022' +tweet_id: '1505269883038158848' +author_username: archtechx +created_at: 2022-03-19T19:48:01+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/php-traits-can-contain-abstract-methods.md b/content/tips/php-traits-can-contain-abstract-methods.md new file mode 100644 index 0000000..50fcd32 --- /dev/null +++ b/content/tips/php-traits-can-contain-abstract-methods.md @@ -0,0 +1,15 @@ +--- +title: 'PHP traits can contain abstract methods' +tweet_id: '1505269900352258049' +thread_slug: weekly-thread-2022-11 +author_username: mmartin_joo +images: + - 'https://pbs.twimg.com/media/FN-wwBiXMAYfW2D.jpg' +created_at: 2022-03-19T19:48:05+00:00 +slug: php-traits-can-contain-abstract-methods +--- +๐Ÿ’กDid you know you can write abstract methods in a trait? + +This way you don't have to make assumptions about the models where the trait is used. + +But instead, you have a clear contract: \ No newline at end of file diff --git a/content/tips/you-can-define-casts-for-specific-eloquent-queries.md b/content/tips/you-can-define-casts-for-specific-eloquent-queries.md new file mode 100644 index 0000000..4a7e18d --- /dev/null +++ b/content/tips/you-can-define-casts-for-specific-eloquent-queries.md @@ -0,0 +1,13 @@ +--- +title: 'You can define casts for specific Eloquent queries' +tweet_id: '1505269894434021376' +thread_slug: weekly-thread-2022-11 +author_username: cosmeescobedo +images: + - 'https://pbs.twimg.com/media/FNwBsytVkAAovTB.jpg' +created_at: 2022-03-19T19:48:04+00:00 +slug: you-can-define-casts-for-specific-eloquent-queries +--- +๐Ÿ”ฅ #Laravel Query Time Casting + +We all know you can add casts to your eloquent models, but did you know you can add casts to a specific query? \ No newline at end of file diff --git a/content/tips/you-can-pass-variables-to-blade-views-using-the-withfoobar-syntax.md b/content/tips/you-can-pass-variables-to-blade-views-using-the-withfoobar-syntax.md new file mode 100644 index 0000000..fba75a6 --- /dev/null +++ b/content/tips/you-can-pass-variables-to-blade-views-using-the-withfoobar-syntax.md @@ -0,0 +1,11 @@ +--- +title: 'You can pass variables to Blade views using the `withFoo($bar)` syntax ' +tweet_id: '1505269888616591363' +thread_slug: weekly-thread-2022-11 +author_username: aschmelyun +images: + - 'https://pbs.twimg.com/media/FNweUY-XMAQg4RV.jpg' +created_at: 2022-03-19T19:48:02+00:00 +slug: you-can-pass-variables-to-blade-views-using-the-withfoobar-syntax +--- +I had no idea that you could pass data into Laravel responses using with{Variable} magic methods! I kind of like this way a little better... \ No newline at end of file diff --git a/content/tips/you-can-use-docblocks-in-blade-files-to-add-ide-support.md b/content/tips/you-can-use-docblocks-in-blade-files-to-add-ide-support.md new file mode 100644 index 0000000..5a7e875 --- /dev/null +++ b/content/tips/you-can-use-docblocks-in-blade-files-to-add-ide-support.md @@ -0,0 +1,15 @@ +--- +title: 'You can use docblocks in Blade files to add IDE support' +tweet_id: '1505269903317635073' +thread_slug: weekly-thread-2022-11 +author_username: freekmurze +images: + - 'https://pbs.twimg.com/media/FN9sAF-XIAA26u3.jpg' +created_at: 2022-03-19T19:48:06+00:00 +slug: you-can-use-docblocks-in-blade-files-to-add-ide-support +--- +๐Ÿ”ฅ Want to have some autocompletion in Blade? + +You can just add a doc block ๐Ÿ‘ + +#laravel #php \ No newline at end of file diff --git a/content/tips/you-can-use-native-php-functions-like-fopen-and-fread-to-interact-directly-with-file-streams.md b/content/tips/you-can-use-native-php-functions-like-fopen-and-fread-to-interact-directly-with-file-streams.md new file mode 100644 index 0000000..70ce7e6 --- /dev/null +++ b/content/tips/you-can-use-native-php-functions-like-fopen-and-fread-to-interact-directly-with-file-streams.md @@ -0,0 +1,17 @@ +--- +title: 'You can use native PHP functions like `fopen` and `fread` to interact directly with file *streams*' +tweet_id: '1505269897340731395' +thread_slug: weekly-thread-2022-11 +author_username: aarondfrancis +images: + - 'https://pbs.twimg.com/media/FN1LRG-WYAgu4aT.jpg' +created_at: 2022-03-19T19:48:04+00:00 +slug: you-can-use-native-php-functions-like-fopen-and-fread-to-interact-directly-with-file-streams +--- +One of my favorite things about using S3 in PHP is that you can register a stream wrapper to interact with files. + +You can use the native PHP functions like fopen, fread, etc. + +Very helpful when you have massive files you don't want to load into memory! + +(CSVs are a use case.) \ No newline at end of file diff --git a/content/tips/you-can-use-partial-queue-fakes.md b/content/tips/you-can-use-partial-queue-fakes.md new file mode 100644 index 0000000..fef02b5 --- /dev/null +++ b/content/tips/you-can-use-partial-queue-fakes.md @@ -0,0 +1,12 @@ +--- +title: 'You can use partial Queue fakes' +tweet_id: '1505269909160280065' +thread_slug: weekly-thread-2022-11 +author_username: djgeisi +images: + - 'https://pbs.twimg.com/media/FN6W5X6XEAAGlnB.jpg' +created_at: 2022-03-19T19:48:07+00:00 +slug: you-can-use-partial-queue-fakes +--- +#Laravel Tip: +Since todays Laravel 9.5 release you can now do partially queue faking. \ No newline at end of file diff --git a/content/tips/you-can-use-pluck-directly-on-eloquent-classes-no-need-to-query-the-instances-first.md b/content/tips/you-can-use-pluck-directly-on-eloquent-classes-no-need-to-query-the-instances-first.md new file mode 100644 index 0000000..cd6928b --- /dev/null +++ b/content/tips/you-can-use-pluck-directly-on-eloquent-classes-no-need-to-query-the-instances-first.md @@ -0,0 +1,11 @@ +--- +title: 'You can use `pluck` directly on Eloquent *classes* โ€” no need to query the instances first' +tweet_id: '1505269885760249857' +thread_slug: weekly-thread-2022-11 +author_username: ecrmnn +images: + - 'https://pbs.twimg.com/media/FOECA3KVgBI8ja2.jpg' +created_at: 2022-03-19T19:48:01+00:00 +slug: you-can-use-pluck-directly-on-eloquent-classes-no-need-to-query-the-instances-first +--- +Calling pluck directly on a model is the most performant way to retrieve a single column from all models in Laravel. Calling get/all before pluck will read all models into memory before plucking the value. \ No newline at end of file diff --git a/content/tips/you-can-use-this-gtmock-in-pest-tests.md b/content/tips/you-can-use-this-gtmock-in-pest-tests.md new file mode 100644 index 0000000..fe92498 --- /dev/null +++ b/content/tips/you-can-use-this-gtmock-in-pest-tests.md @@ -0,0 +1,11 @@ +--- +title: 'You can use $this->mock in Pest tests' +tweet_id: '1505269906157187072' +thread_slug: weekly-thread-2022-11 +author_username: enunomaduro +images: + - 'https://pbs.twimg.com/media/FN-0CQaWUAYsMxv.jpg' +created_at: 2022-03-19T19:48:06+00:00 +slug: you-can-use-this-gtmock-in-pest-tests +--- +Within your Pest / PHPUnit tests, you may use @laravelphp's "mock" method to instruct the container to use your mocked instance of the object instead of constructing the object itself. โœ… \ No newline at end of file diff --git a/content/tips/you-can-validate-data-at-the-database-level.md b/content/tips/you-can-validate-data-at-the-database-level.md new file mode 100644 index 0000000..31faf84 --- /dev/null +++ b/content/tips/you-can-validate-data-at-the-database-level.md @@ -0,0 +1,13 @@ +--- +title: 'You can validate data at the database level' +tweet_id: '1505269891535818754' +thread_slug: weekly-thread-2022-11 +author_username: tobias_petry +images: + - 'https://pbs.twimg.com/media/FN-JmJCXEAUCQjy.jpg' +created_at: 2022-03-19T19:48:03+00:00 +slug: you-can-validate-data-at-the-database-level +--- +โšก๏ธ Database Tip + +Your application will have bugs and any data stored may be corrupt forever. But with constraints on the data model, rules would have prevented saving incorrect data in the first place! Use them as a last frontier to make sure you always have valid data. \ No newline at end of file