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

Weekly thread #4 (#26)

* Use Author::updateOrCreate instead of firstOrCreate

* Weekly tips #4
This commit is contained in:
lukinovec 2022-01-28 18:03:12 +01:00 committed by GitHub
parent f1e283e142
commit e907eba3dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 140 additions and 4 deletions

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