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

Weekly tips #4

This commit is contained in:
lukinovec 2022-01-28 17:36:41 +01:00
parent 72fff055f4
commit 018ed8a873
15 changed files with 139 additions and 3 deletions

View file

@ -1,5 +1,5 @@
--- ---
username: alexjgarrett username: alexjgarrett
avatar: 'https://pbs.twimg.com/profile_images/1481608755590615042/Z0usTfe-_normal.jpg'
name: 'Alex Garrett-Smith' name: 'Alex Garrett-Smith'
avatar: 'https://pbs.twimg.com/profile_images/860958772671500289/63kCnhYX_normal.jpg'
--- ---

View file

@ -0,0 +1,5 @@
---
username: austencam
name: 'Austen Cameron'
avatar: 'https://pbs.twimg.com/profile_images/1398382260542390279/83-mTSq1_normal.jpg'
---

View file

@ -1,5 +1,5 @@
--- ---
username: bhaidar username: bhaidar
name: 'Bilal Haidar . Laravel Enthusiast'
avatar: 'https://pbs.twimg.com/profile_images/1381347341400215552/LvVOFV9__normal.jpg' avatar: 'https://pbs.twimg.com/profile_images/1381347341400215552/LvVOFV9__normal.jpg'
name: 'Bilal Haidar | Laravel Enthusiast'
--- ---

View file

@ -0,0 +1,5 @@
---
username: cerbero90
name: 'Andrea Marco Sartori'
avatar: 'https://pbs.twimg.com/profile_images/956500408377139200/QkHAZFZ9_normal.jpg'
---

View file

@ -1,5 +1,5 @@
--- ---
username: tobias_petry username: tobias_petry
name: 'Tobias Petry'
avatar: 'https://pbs.twimg.com/profile_images/1449987893980766209/iPIfnmTE_normal.jpg' avatar: 'https://pbs.twimg.com/profile_images/1449987893980766209/iPIfnmTE_normal.jpg'
name: Tobias_Petry.sql
--- ---

View file

@ -0,0 +1,11 @@
---
slug: weekly-thread-2022-04
title: 'Weekly thread #04 of 2022'
tweet_id: '1487081923289640961'
author_username: archtechx
created_at: 2022-01-28T16:33:49+00:00
links: { }
---
🔥 This week's code tips for Laravel developers
A weekly thread 🧵

View file

@ -0,0 +1,11 @@
---
title: 'Convert email addresses to full names with the help of Str::headline()'
tweet_id: '1487081950900736012'
thread_slug: weekly-thread-2022-04
author_username: SteveTheBauman
images:
- 'https://pbs.twimg.com/media/FKDXqE8XoAU5xO8.jpg'
created_at: 2022-01-28T15:15:40+00:00
slug: convert-email-addresses-to-full-names-with-the-help-of-strheadline
---
Ran into a great use-case for Str::headline() -- Generating displayable usernames from email addresses 👌

View file

@ -0,0 +1,13 @@
---
title: 'Higher-order messages are a great way to tidy up long collection logic'
tweet_id: '1487081947864002572'
thread_slug: weekly-thread-2022-04
author_username: alexjgarrett
images:
- 'https://pbs.twimg.com/media/FKD7ajmXIAAEjTW.jpg'
created_at: 2022-01-28T15:15:39+00:00
slug: higher-order-messages-are-a-great-way-to-tidy-up-long-collection-logic
---
Sometimes I forget about higher order collection messages in Laravel, but they're a great way to shorten and tidy up your code ✨
Here's a simplified (and not recommended) example.

View file

@ -0,0 +1,15 @@
---
title: 'Laravel''s container can be used for resolving variadic dependencies'
tweet_id: '1487081929123897344'
thread_slug: weekly-thread-2022-04
author_username: cerbero90
images:
- 'https://pbs.twimg.com/media/FJ7_971aUAoMZF5.png'
created_at: 2022-01-28T15:15:35+00:00
slug: laravels-container-can-be-used-for-resolving-variadic-dependencies
---
Since @laravelphp 8.79 it is possible to resolve variadic dependencies out of the IoC container.
This is quite useful for type-hinting and static analysis and allows us to bind a set of concrete implementations to an abstraction layer.
#Laravel #PHP

View file

@ -0,0 +1,11 @@
---
title: 'The value() helper returns the passed value UNLESS it''s invokable — then it first calls it'
tweet_id: '1487081938623995912'
thread_slug: weekly-thread-2022-04
author_username: marcelpociot
images:
- 'https://pbs.twimg.com/media/FJ-5q6EWQAMKjpX.jpg'
created_at: 2022-01-28T15:15:37+00:00
slug: the-value-helper-returns-the-passed-value-unless-its-invokable-then-it-first-calls-it
---
I absolutely love the little "value" helper method in @laravelphp as it allows you to create beautiful APIs with ease under the hood.

View file

@ -0,0 +1,13 @@
---
title: 'Use Eloquent scopes to clean up complex relation queries'
tweet_id: '1487081935478276103'
thread_slug: weekly-thread-2022-04
author_username: archtechx
images:
- 'https://pbs.twimg.com/media/FKCIrumVQAcD8RB.jpg'
created_at: 2022-01-28T15:15:36+00:00
slug: use-eloquent-scopes-to-clean-up-complex-relation-queries
---
🔥 Eloquent scopes pair very well with complex relation queries
Scopes should also have @method annotations. They make the model more self-documenting & better supported in IDEs

View file

@ -0,0 +1,13 @@
---
title: 'Use PostgreSQL''s trigram indexes to make WHERE LIKE queries faster'
tweet_id: '1487081932202463236'
thread_slug: weekly-thread-2022-04
author_username: tobias_petry
images:
- 'https://pbs.twimg.com/media/FKB7gJiWQAwc5QS.jpg'
created_at: 2022-01-28T15:15:35+00:00
slug: use-postgresqls-trigram-indexes-to-make-where-like-queries-faster
---
⚡️ Database Tip
Every database performance guide is repeating the false statement stating WHERE LIKE '%search%' queries can't use an index. That is just not true! Most probably your database can't, but PostgreSQL implements trigram indexes which will make this really fast!

View file

@ -0,0 +1,13 @@
---
title: 'Use Tailwind''s color opacity modifier to change the background color and opacity in a single class'
tweet_id: '1487081941711028227'
thread_slug: weekly-thread-2022-04
author_username: austencam
images:
- 'https://pbs.twimg.com/media/FKJYn3PUYAEecqU.jpg'
created_at: 2022-01-28T15:15:38+00:00
slug: use-tailwinds-color-opacity-modifier-to-change-the-background-color-and-opacity-in-a-single-class
---
✨Did you know Tailwind CSS has a shorthand syntax for background, border, and text opacity?
🔗 https://tailwindcss.com/docs/background-color#changing-the-opacity

View file

@ -0,0 +1,13 @@
---
title: 'You can use the date helper on the Request class to retrieve a value as a Carbon instance'
tweet_id: '1487081926103945217'
thread_slug: weekly-thread-2022-04
author_username: mmartin_joo
images:
- 'https://pbs.twimg.com/media/FJ49UFhWYAEWFyu.jpg'
created_at: 2022-01-28T15:15:34+00:00
slug: you-can-use-the-date-helper-on-the-request-class-to-retrieve-a-value-as-a-carbon-instance
---
💡There's a really helpful date helper on the Request class.
You can retrieve a value as a Carbon instance:

View file

@ -0,0 +1,13 @@
---
title: 'You can use useCurrent() & useCurrentOnUpdate() on timestamp fields in your migrations'
tweet_id: '1487081944777035777'
thread_slug: weekly-thread-2022-04
author_username: bhaidar
images:
- 'https://pbs.twimg.com/media/FJX3Lg1VUAEvcQH.jpg'
created_at: 2022-01-28T15:15:38+00:00
slug: you-can-use-usecurrent-usecurrentonupdate-on-timestamp-fields-in-your-migrations
---
🌶️ #Laravel tip: When using timestamp() columns in Laravel Migrations, append the useCurrent() & useCurrentOnUpdate() to set timestamp columns' default value to CURRENT_TIMESTAMP
#PHP #Developers