1
0
Fork 0
mirror of https://github.com/archtechx/laravel-tips.git synced 2025-12-12 05:14:04 +00:00
This commit is contained in:
lukinovec 2022-04-25 12:53:33 +02:00
commit 5afa27cc7c
43 changed files with 468 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
username: BurtDS
name: 'Bert De Swaef'
avatar: 'https://pbs.twimg.com/profile_images/1042044375688196097/Ktoa7v3p_normal.jpg'
---

View file

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

View file

@ -0,0 +1,5 @@
---
username: joemasilotti
name: 'Joe Masilotti 📗'
avatar: 'https://pbs.twimg.com/profile_images/1469703667791982596/5-0pGyNV_normal.jpg'
---

View file

@ -0,0 +1,5 @@
---
username: laravelnews
name: 'Laravel News'
avatar: 'https://pbs.twimg.com/profile_images/1359866716222861317/coQ-RmRS_normal.jpg'
---

View file

@ -1,5 +1,5 @@
--- ---
username: ryangjchandler username: ryangjchandler
avatar: 'https://pbs.twimg.com/profile_images/1512466908746235904/6jQdQZim_normal.png'
name: 'Ryan Chandler' name: 'Ryan Chandler'
avatar: 'https://pbs.twimg.com/profile_images/1446231529986961410/X5zL_n0h_normal.jpg'
--- ---

View file

@ -0,0 +1,5 @@
---
username: victoryoalli
name: '🧔🏻Victor Yoalli'
avatar: 'https://pbs.twimg.com/profile_images/1511729912297627657/LmidlmsF_normal.png'
---

View file

@ -0,0 +1,5 @@
---
username: zepfietje
name: 'Zep Fietje'
avatar: 'https://pbs.twimg.com/profile_images/1486773319189815314/VstRGufn_normal.jpg'
---

View file

@ -0,0 +1,11 @@
---
slug: weekly-thread-2022-12
title: 'Weekly thread #12 of 2022'
tweet_id: '1507455535322308610'
author_username: archtechx
created_at: 2022-03-25T20:33:01+00:00
links: { }
---
🔥 This week's code tips for Laravel developers
A weekly thread 🧵

View file

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

View file

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

View file

@ -0,0 +1,11 @@
---
slug: weekly-thread-2022-15
title: 'Weekly thread #15 of 2022'
tweet_id: '1515057381511610368'
author_username: archtechx
created_at: 2022-04-15T20:00:02+00:00
links: { }
---
🔥 This week's code tips for Laravel developers
A weekly thread 🧵

View file

@ -0,0 +1,14 @@
---
title: 'If you use both pest and PHPUnit, you can use both syntaxes in both types of tests'
tweet_id: '1507455564942495749'
thread_slug: weekly-thread-2022-12
author_username: djgeisi
images:
- 'https://pbs.twimg.com/media/FOUNAdFXMAQI7RA.jpg'
created_at: 2022-03-25T20:33:08+00:00
slug: if-you-use-both-pest-and-phpunit-you-can-use-both-syntaxes-in-both-types-of-tests
---
#PestPHP #PHP Tip
If you have a mixed codebase with Pest and PHPUnit tests you can use almost all of the pest magic in your PHPUnit tests.
It just works.

View file

@ -0,0 +1,15 @@
---
title: 'Improve the DX of your commands by making arguments optional and prompting the user when they''re empty'
tweet_id: '1515057387027140609'
thread_slug: weekly-thread-2022-15
author_username: mmartin_joo
images:
- 'https://pbs.twimg.com/media/FQAcwOkWUAESOwS.jpg'
created_at: 2022-04-15T20:00:04+00:00
slug: improve-the-dx-of-your-commands-by-making-arguments-optional-and-prompting-the-user-when-theyre-empty
---
💡 Just a quick tip: define every argument of commands as optional and ask for input if they are missing.
This way, you dont need to think about the arguments when running a command.
Just run it, and it will ask everything:

View file

@ -0,0 +1,11 @@
---
title: 'In scheduled tasks, you can use `onSuccess` and `onFailure` callbacks'
tweet_id: '1515057395763798018'
thread_slug: weekly-thread-2022-15
author_username: cosmeescobedo
images:
- 'https://pbs.twimg.com/media/FQAK8H-XEAMWMMT.jpg'
created_at: 2022-04-15T20:00:06+00:00
slug: in-scheduled-tasks-you-can-use-onsuccess-and-onfailure-callbacks
---
🔥 Laravel Tip: You can specify what to do if a scheduled task fails or succeeds.

View file

@ -0,0 +1,11 @@
---
title: 'isset() accepts multiple arguments'
tweet_id: '1507455541072728066'
thread_slug: weekly-thread-2022-12
author_username: laravelnews
images:
- 'https://pbs.twimg.com/media/FOqbrYAX0AgsSNL.jpg'
created_at: 2022-03-25T20:33:02+00:00
slug: isset-accepts-multiple-arguments
---
It's a minor thing but the PHP `isset` function can accept multiple vars. https://www.instagram.com/p/CbctwMxgPv4/

View file

@ -0,0 +1,11 @@
---
title: 'Pest allows calling dd() directly on the expect() chain'
tweet_id: '1507455561918390279'
thread_slug: weekly-thread-2022-12
author_username: enunomaduro
images:
- 'https://pbs.twimg.com/media/FOibegNXsAEKTbb.jpg'
created_at: 2022-03-25T20:33:07+00:00
slug: pest-allows-calling-dd-directly-on-the-expect-chain
---
Pest tip: Use the `dd` method to dump the current expectation value and end the test suite. 🔦

View file

@ -0,0 +1,13 @@
---
title: 'The `shouldCache()` method lets you cache model accessor values'
tweet_id: '1515057389950537729'
thread_slug: weekly-thread-2022-15
author_username: cosmeescobedo
images:
- 'https://pbs.twimg.com/media/FQOpEt5VQA0OnWt.jpg'
created_at: 2022-04-15T20:00:04+00:00
slug: the-shouldcache-method-lets-you-cache-model-accessor-values
---
🔥 Laravel Tip: Accessor Caching
As of Laravel 9.6, if you have a computationally intensive accessor, you can use the shouldCache method.

View file

@ -0,0 +1,11 @@
---
title: 'The spread syntax understands named parameters and correctly assigns array values to them'
tweet_id: '1515057384204382208'
thread_slug: weekly-thread-2022-15
author_username: SteveTheBauman
images:
- 'https://pbs.twimg.com/media/FQJ4FUcX0A01ZUZ.jpg'
created_at: 2022-04-15T20:00:03+00:00
slug: the-spread-syntax-understands-named-parameters-and-correctly-assigns-array-values-to-them
---
Today I learned that PHP will insert callback parameters in the order of their defined name, when spreading an array of args with string keys, allowing you to place them in any position in the callback. Super cool! 💪

View file

@ -0,0 +1,11 @@
---
title: 'Understand the difference between `fresh()` and `refresh()`. One returns a *fresh* new instance, while the other *refreshes* an existing instance'
tweet_id: '1509994020109316096'
thread_slug: weekly-thread-2022-13
author_username: mattkingshott
images:
- 'https://pbs.twimg.com/media/FPBT9FCXoAUMen2.jpg'
created_at: 2022-04-01T20:40:03+00:00
slug: understand-the-difference-between-fresh-and-refresh-one-returns-a-fresh-new-instance-while-the-other-refreshes-an-existing-instance
---
🔥 #Laravel Tip: Ever wondered what the differences are between an Eloquent models fresh() and refresh() methods? Lets see what each of them do with this little cheatsheet.

View file

@ -0,0 +1,13 @@
---
title: 'Use the `ShouldBeEncrypted` interface on a job class to make Laravel encrypt the job''s payload'
tweet_id: '1507455546978287617'
thread_slug: weekly-thread-2022-12
author_username: cosmeescobedo
images:
- 'https://pbs.twimg.com/media/FOG28lHUcAAk6Om.jpg'
created_at: 2022-03-25T20:33:04+00:00
slug: use-the-shouldbeencrypted-interface-on-a-job-class-to-make-laravel-encrypt-the-jobs-payload
---
🔥 #Laravel Job Encryption
Since Laravel v8.19.0, you can add the `ShouldBeEncrypted` interface to your job class. Laravel will encrypt the job's payload automatically.

View file

@ -0,0 +1,13 @@
---
title: 'You can associate an input with a form using the form= attribute'
tweet_id: '1512463810069598212'
thread_slug: weekly-thread-2022-14
author_username: joemasilotti
images:
- 'https://pbs.twimg.com/media/FPh2K65VQAQO5xz.jpg'
created_at: 2022-04-08T16:14:07+00:00
slug: you-can-associate-an-input-with-a-form-using-the-form-attribute
---
Wait... what?! 🤯
https://www.smashingmagazine.com/2022/03/html-attributes-you-never-use/#the-form-attribute-for-form-fields

View file

@ -0,0 +1,13 @@
---
title: 'You can calculate the `age()` of Carbon instances'
tweet_id: '1512463795364384771'
thread_slug: weekly-thread-2022-14
author_username: victoryoalli
images:
- 'https://pbs.twimg.com/media/FPh7dVyWUAEW5EQ.jpg'
created_at: 2022-04-08T16:14:03+00:00
slug: you-can-calculate-the-age-of-carbon-instances
---
#TIL How to calculate the age using a date in Laravel or using Carbon.
#LaravelTip #PHPTip #dev

View file

@ -0,0 +1,11 @@
---
title: 'You can call `squish()` on Stringable instances to remove all unnecessary whitespaces'
tweet_id: '1512463789215477763'
thread_slug: weekly-thread-2022-14
author_username: mattkingshott
images:
- 'https://pbs.twimg.com/media/FPqzjjnWUAAolDJ.jpg'
created_at: 2022-04-08T16:14:02+00:00
slug: you-can-call-squish-on-stringable-instances-to-remove-all-unnecessary-whitespaces
---
🔥 #Laravel Tip: Hot off the press, the latest release includes the squish global helper method by @DwightConrad. It removes all extraneous white space from a string, including between words. Its like trim on steroids :)

View file

@ -0,0 +1,14 @@
---
title: 'You can call `withTrashed()` on a route to accept soft deleted models'
tweet_id: '1512463792432566274'
thread_slug: weekly-thread-2022-14
author_username: cosmeescobedo
images:
- 'https://pbs.twimg.com/media/FPizAZxVsAUl-WZ.jpg'
created_at: 2022-04-08T16:14:02+00:00
slug: you-can-call-withtrashed-on-a-route-to-accept-soft-deleted-models
---
🔥 Laravel Tip: Route model binding soft-deleted models
By default, when using route model binding will not retrieve models that have been soft-deleted.
You can change that behavior by using `withTrashed` in your route.

View file

@ -0,0 +1,11 @@
---
title: 'You can clear all Laravel caches using `optimize:clear`'
tweet_id: '1507455552892268546'
thread_slug: weekly-thread-2022-12
author_username: aschmelyun
images:
- 'https://pbs.twimg.com/media/FOeOo81WYAUa42D.jpg'
created_at: 2022-03-25T20:33:05+00:00
slug: you-can-clear-all-laravel-caches-using-optimizeclear
---
Just found out there's a single artisan command to clear out all Laravel caches, much less typing!

View file

@ -0,0 +1,15 @@
---
title: 'You can create DB indices for transformed versions of columns'
tweet_id: '1512463807167139846'
thread_slug: weekly-thread-2022-14
author_username: tobias_petry
images:
- 'https://pbs.twimg.com/media/FPk6CjSWYAAXwyn.jpg'
created_at: 2022-04-08T16:14:06+00:00
slug: you-can-create-db-indices-for-transformed-versions-of-columns
---
⚡️ Database Tip
Most developers are puzzled that indexes are not used for e.g. WHERE LOWER(email) = ?. But contrary to common belief, an index can be created for these cases! It's called a function-based index and is supported by MySQL and PostgreSQL.
https://sqlfordevs.io/tips/function-based-index

View file

@ -0,0 +1,11 @@
---
title: 'You can create Storage disks on the fly'
tweet_id: '1512463804205973508'
thread_slug: weekly-thread-2022-14
author_username: ryangjchandler
images:
- 'https://pbs.twimg.com/media/FPwqSygWYAAbSUh.jpg'
created_at: 2022-04-08T16:14:05+00:00
slug: you-can-create-storage-disks-on-the-fly
---
🔥 Did you know that you can create Storage disks on the fly in @laravelphp? This is super useful when you want your user to provide their own filesystem credentials, e.g. a user can bring their own S3 bucket to your app.

View file

@ -0,0 +1,16 @@
---
title: 'You can debounce a function using Alpine.debounce()'
tweet_id: '1507455555899564032'
thread_slug: weekly-thread-2022-12
author_username: zepfietje
images: { }
created_at: 2022-03-25T20:33:06+00:00
slug: you-can-debounce-a-function-using-alpinedebounce
---
❓ Using Alpine.js and need to debounce a function?
❌ You don't need JavaScript libraries like lodash.
✅ Just use Alpine.debounce() which is also used internally for the x-on:input.debounce="" modifier.
Cc: @calebporzio

View file

@ -0,0 +1,15 @@
---
title: 'You can freeze time in tests'
tweet_id: '1509994017227886594'
thread_slug: weekly-thread-2022-13
author_username: AshAllenDesign
images:
- 'https://pbs.twimg.com/media/FO8k5kAWYAAip2V.jpg'
created_at: 2022-04-01T20:40:02+00:00
slug: you-can-freeze-time-in-tests
---
In your Laravel tests, you might sometimes need to freeze the time.
This is particularly useful if you're trying to make assertions based on timestamps or need to make queries based on dates and/or times.
#laravel #php

View file

@ -0,0 +1,13 @@
---
title: 'You can generate a series of dates in a given range right at the database level'
tweet_id: '1507455559049822208'
thread_slug: weekly-thread-2022-12
author_username: tobias_petry
images:
- 'https://pbs.twimg.com/media/FOih4zwWQAsjZ-E.jpg'
created_at: 2022-03-25T20:33:07+00:00
slug: you-can-generate-a-series-of-dates-in-a-given-range-right-at-the-database-level
---
⚡️ Database Tip
When doing statistical aggregations by time, you may have gaps in your data. You don't have to fill them manually with code! You can generate a series of dates from a start to end time and use these days to join to your statistical data with gaps.

View file

@ -0,0 +1,11 @@
---
title: 'You can generate fake images using Faker'
tweet_id: '1515057392890769410'
thread_slug: weekly-thread-2022-15
author_username: justsanjit
images:
- 'https://pbs.twimg.com/media/FQOhGy6XEAMYB-X.jpg'
created_at: 2022-04-15T20:00:05+00:00
slug: you-can-generate-fake-images-using-faker
---
#Laravel #PHP Tip 🔥 You can use #faker to not only generate text values but also fake images.

View file

@ -0,0 +1,14 @@
---
title: 'You can now call `newLine()` on Stringable instances'
tweet_id: '1509994032033804290'
thread_slug: weekly-thread-2022-13
author_username: djgeisi
images:
- 'https://pbs.twimg.com/media/FPCdrxkWUAASAm5.jpg'
created_at: 2022-04-01T20:40:06+00:00
slug: you-can-now-call-newline-on-stringable-instances
---
#PHP #Laravel
Since todays Laravel 9.6 release a new newline() method was added to the Stringable Class.
Thanks to @paulandroshchuk who contributed this

View file

@ -0,0 +1,11 @@
---
title: 'You can process the output of scheduled tasks: send an email or write to a file'
tweet_id: '1515057398687313920'
thread_slug: weekly-thread-2022-15
author_username: justsanjit
images:
- 'https://pbs.twimg.com/media/FQHMYW4WQAIxF69.jpg'
created_at: 2022-04-15T20:00:06+00:00
slug: you-can-process-the-output-of-scheduled-tasks-send-an-email-or-write-to-a-file
---
#Laravel Tip 🔥 Few convenient methods to work with the output of scheduled tasks.

View file

@ -0,0 +1,11 @@
---
title: 'You can queue Closures'
tweet_id: '1509994028997169158'
thread_slug: weekly-thread-2022-13
author_username: alexjgarrett
images:
- 'https://pbs.twimg.com/media/FO7OX-ZX0AEQooG.jpg'
created_at: 2022-04-01T20:40:05+00:00
slug: you-can-queue-closures
---
I had no idea you could queue closures in @laravelphp until today.

View file

@ -0,0 +1,11 @@
---
title: 'You can record all login & logout events'
tweet_id: '1507455544021250049'
thread_slug: weekly-thread-2022-12
author_username: mattkingshott
images:
- 'https://pbs.twimg.com/media/FOoOjf-XIAMPLIW.jpg'
created_at: 2022-03-25T20:33:03+00:00
slug: you-can-record-all-login-logout-events
---
🔥 #Laravel Tip: If your app needs to record logins and logouts for security purposes (auditing), then you should definitely make use of the auth events, which allow you to easily listen for them.

View file

@ -0,0 +1,11 @@
---
title: 'You can remove all falsy values from a Collection by calling filter() without any arguments'
tweet_id: '1507455538078003203'
thread_slug: weekly-thread-2022-12
author_username: ecrmnn
images:
- 'https://pbs.twimg.com/media/FOYvPYuWQAoA-2P.jpg'
created_at: 2022-03-25T20:33:02+00:00
slug: you-can-remove-all-falsy-values-from-a-collection-by-calling-filter-without-any-arguments
---
Laravel Collections tip. To remove all falsy values from the collection, simply call filter without any arguments ✨

View file

@ -0,0 +1,11 @@
---
title: 'You can start testing Livewire components with basic tests that makes sure components render accurately'
tweet_id: '1507455550027563009'
thread_slug: weekly-thread-2022-12
author_username: ryangjchandler
images:
- 'https://pbs.twimg.com/media/FOPGoowXEAE883f.jpg'
created_at: 2022-03-25T20:33:04+00:00
slug: you-can-start-testing-livewire-components-with-basic-tests-that-makes-sure-components-render-accurately
---
🔥 When you're testing your @LaravelLivewire components, one of the simplest tests you can add is a "can this component be mounted" test. This is one of the best ways to test your the mounting process in isolation and ensuring the component renders the view correctly.

View file

@ -0,0 +1,14 @@
---
title: 'You can temporarily disable timestamps when saving a model'
tweet_id: '1512463801278291971'
thread_slug: weekly-thread-2022-14
author_username: BurtDS
images:
- 'https://pbs.twimg.com/media/FPe3PztWQAIaXzC.jpg'
created_at: 2022-04-08T16:14:05+00:00
slug: you-can-temporarily-disable-timestamps-when-saving-a-model
---
📝 #Laravel Tip | In some cases you don't want the updated_at field the change when updating small things. .. Did you know you could disable the timestamps while saving your data?
Here is how... 🔥
#laraveltip #php #code #development #details

View file

@ -0,0 +1,11 @@
---
title: 'You can transform variables passed to translation strings right in language files'
tweet_id: '1509994034877534212'
thread_slug: weekly-thread-2022-13
author_username: ecrmnn
images:
- 'https://pbs.twimg.com/media/FPB_HCDXsAUhtvh.jpg'
created_at: 2022-04-01T20:40:06+00:00
slug: you-can-transform-variables-passed-to-translation-strings-right-in-language-files
---
Did you know that translation variables can easily be capitalized or converterd to lowercase and uppcase in Laravel? 🆙🌍

View file

@ -0,0 +1,11 @@
---
title: 'You can use constrained eager loading to increase performance of database queries that use relations'
tweet_id: '1509994025926885381'
thread_slug: weekly-thread-2022-13
author_username: mattkingshott
images:
- 'https://pbs.twimg.com/media/FOsQc3JXEAgF1P6.jpg'
created_at: 2022-04-01T20:40:04+00:00
slug: you-can-use-constrained-eager-loading-to-increase-performance-of-database-queries-that-use-relations
---
🔥 #Laravel Tip: Eager loading a models relationships is a great way to improve performance / avoid the N+1 problem. However, you can go further… with constrained eager loading you can tell Laravel to only load the related records you actually need.

View file

@ -0,0 +1,15 @@
---
title: 'You can use `Notification::assertNothingSentTo()` to check that no notifications were sent to a specific user/notifiable model'
tweet_id: '1509994037830332416'
thread_slug: weekly-thread-2022-13
author_username: AshAllenDesign
images:
- 'https://pbs.twimg.com/media/FO8nW9TXsBExZTp.jpg'
created_at: 2022-04-01T20:40:07+00:00
slug: you-can-use-notificationassertnothingsentto-to-check-that-no-notifications-were-sent-to-a-specific-usernotifiable-model
---
🚀 You can now use the new "assertNothingSentTo" method in your Laravel tests.
You can use this to ensure that no notifications were sent to a given notifiable model (or models)!
#laravel #php

View file

@ -0,0 +1,13 @@
---
title: 'You can use the `missing` method to customize 404 handling on a route'
tweet_id: '1512463798287814658'
thread_slug: weekly-thread-2022-14
author_username: cosmeescobedo
images:
- 'https://pbs.twimg.com/media/FPi0WYWUYAQXuWf.jpg'
created_at: 2022-04-08T16:14:04+00:00
slug: you-can-use-the-missing-method-to-customize-404-handling-on-a-route
---
🔥 Laravel tip: Customizing Missing Model Behavior in route model bindings
By default, Laravel throws a 404 error when it can't bind the model, but you can change that behavior by passing a closure to the missing method.

View file

@ -0,0 +1,11 @@
---
title: 'You can use use `whereBetween` to filter for records between two timestamps'
tweet_id: '1509994023083147264'
thread_slug: weekly-thread-2022-13
author_username: ecrmnn
images:
- 'https://pbs.twimg.com/media/FO8rgMGXsAkX0SD.jpg'
created_at: 2022-04-01T20:40:04+00:00
slug: you-can-use-use-wherebetween-to-filter-for-records-between-two-timestamps
---
How to retrieve records between two timestamps in Laravel 🗓 Use whereBetween with a from and to date. If you need to provide fallback you can do so with the nullish coalescing operator ❔❔