Godfred Boateng Addai retweeted
Replying to @MrPunyapal @mmillis1
In most cases, this is a very good reason not to use auth()->user() inside actions or services.
Business logic (Actions and services) Are usually called from both the http layer and cli layer. It will be better to inject a user model which then fixes this problem.
Controllers can get auth user, console commands can fetch the required user then jobs, services or actions don't need to be tied to the auth session.
Godfred Boateng Addai retweeted
Sometimes we may want to do some post processing of response or track some instrumentation metrics (e.g. saving transactions in NewRelic) but these can increase our response time which is not good for our users.
Terminable middlewares allows you to do this even after response is sent to the user.
Godfred Boateng Addai retweeted
Did you know that PHP reconnects to Redis on every request? Laravel 12 introduces a new env variable REDIS_PERSISTENT that can maintain Redis connections between requests.
Soon, I'll write a blog article diving deeper into this topic.
Godfred Boateng Addai retweeted
Replying to @PovilasKorop
Don't overthink performance and abstractions especially in small projects. Grow with the project.
Keep It Simple, Stupid - KISS. Understandable code is better than shiny new tricks.
Always be ready to learn, don't let your ego lead the way.
Godfred Boateng Addai retweeted
I remember I had to also find out the hard way myself, sometimes choosing the right ID type is not really given the right attention from the start.
Read about how I choose the right databse key depending on the service: Link below.
Godfred Boateng Addai retweeted
π‘A quick Eloquent Tip
Laravel 8 introduced the Prunable trait. You can use it to delete old models on a scheduled basis.
You don't need to write custom commands anymore:
Godfred Boateng Addai retweeted
Laravel Insider π
We might get a new Number utility class for formatting numbers. What are your thoughts?
There is an active PR by @CodeWithCaen that adds this helper and the initial idea was even endorsed by Taylor
Godfred Boateng Addai retweeted
These days I'm using #Eloquent's touch() more often for simple timestamp updates than the regular update([...]) method. π
Godfred Boateng Addai retweeted
#Laravel Tip
You may use the `push` method to save both model & it's relationship.
For more: hamidafghan.me/blog/laravel-β¦
Godfred Boateng Addai retweeted
A new "ensure" method on collections may now be used to ensure that all elements of the collection are of a given type.
Otherwise, an UnexpectedValueException will be thrown. π¨
Thanks @inxilpro!
Godfred Boateng Addai retweeted
Laravel devs, if you're generating reports that you don't need to keep here are a couple of approaches I've used to get rid of them.
Godfred Boateng Addai retweeted
Godfred Boateng Addai retweeted
#Laravel Tip: You can keep a check on performance leaks during development, using laravel's Strict Mode. It was introduced in Laravel 9.
































