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

Week 11/2022

This commit is contained in:
Samuel Štancl 2022-03-20 20:41:25 +01:00
parent 4af817e2b0
commit b451d14953
12 changed files with 135 additions and 1 deletions

View file

@ -1,5 +1,5 @@
--- ---
username: aarondfrancis 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' name: 'Aaron Francis'
--- ---

View file

@ -0,0 +1,5 @@
---
username: djgeisi
name: 'Tim Geisendoerfer'
avatar: 'https://pbs.twimg.com/profile_images/1417203113551925251/YtYwDdMt_normal.jpg'
---

View file

@ -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 🧵

View file

@ -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:

View file

@ -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?

View file

@ -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...

View file

@ -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

View file

@ -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.)

View file

@ -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.

View file

@ -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.

View file

@ -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. ✅

View file

@ -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.