Internal classes in PHP
Nuno Maduro, engineer at Algolia, explains what is the value of the @internal tag
The PHP @internal tag can be used to denote that the associated class/method is internal to the library. It's supported by PHPStorm and it warns people that those classes/methods are not meant to be used
Read more [nunomaduro.com]
Join 9,500+ smart developers
Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
"Freek publishes a super resourceful and practical newsletter. A must for anyone in the Laravel space"
Bash/Shell Autocompletion for Composer
Bram Van Damme explains how you can get autocompletion for most composer commands.
Read more [www.bram.us]
Parallel PHP: The Next Chapter
Joe Watkins, core contributor and pthreads author, is working on a new threading API for PHP called parallel. It might be a while before it is released.
Recently, I set to work on a new threading API, named Parallel, it is not an exact clone of any existing threading API, it is an API focused on being simple and hiding the complexity inherent in utilising parallelism in your application, it is also focused on being forward compatible with the JIT, for that day when we can actually execute machine code in userland and in parallel.
https://blog.krakjoe.ninja/2019/02/parallel-php-next-chapter.html
EDIT: meanwhile a stable version has been released. You can find it in this repo on GitHub.
Ever wondered what "hydrate" means?
?? Laravel Core Adventures - Did you know?
— Christoph Rumpel ? (@christophrumpel) May 17, 2019
Ever wondered what "hydrate" means? I've been there. Then I realized it's just a fancy word for filling an object with data.
In this Eloquent Builder example, Laravel fills a new collection object with models from an array. pic.twitter.com/D5t0EVnksM
Read more [twitter.com]
Using Eloquent's firstOr
You know `firstOrFail`, `firstOrCreate`, etc in @laravel
— Jeff Madsen (@codebyjeff) May 19, 2019
There's also a simple `firstOr` that will run a callback if not found pic.twitter.com/q7QmPR1y1S
Read more [twitter.com]
Calculating totals in Laravel using conditional aggregates
Jonathan Reinink wrote another awesome post on how to handle a complicated query.
I was asked recently how to calculate multiple totals (aggregates) in Laravel in the most efficient way. For example, maybe you have an email subscription service and want to display various totals based on your subscribers
Read more [reinink.ca]
Exceptional Exceptions
At the Clarabridge Developers blog, Toon Daelman wrote a good post on how to improve your exceptions.
You've made it to this post thinking "Why do we still need to talk about Exceptions?". Well, they're used everywhere in OOP codebases, but sometimes they're used in a way that make debugging a bit difficult. Let's look at some ways to make debugging exceptions a bit more fun!
Read more [engagor.github.io]
Plucking multiple attributes
? Laravel quick tip
— Sebastian De Deyne (@sebdedeyne) May 21, 2019
Use ->map->only on Eloquent collections to pluck multiple attributes pic.twitter.com/z3c1sOox9J
Read more [twitter.com]
A rule to validate delimited data original
laravel-validation-rules is a package that contains handy custom validation rules that are being used in various client projects we made at Spatie. Last week I added a new validate rule called Delimited to the package.
In this blog post, I'd like to explain why we added it and how it can be used.
PHP in 2019
In an awesome post, my colleague Brent explains that PHP is in a very good state nowadays. If you dismissed the language previously, now is a good time to take another look.
PHP managed to evolve quite a bit since the 5.* days. Today I'm addressing the people who are either not programming in PHP anymore, or are stuck in legacy projects.
Read more [stitcher.io]
Making Laravel Scout Imports 64x Faster
Matt Allan explains why using an offset is slow when used on large datasets.
It turns out it’s easy to page through results without using offset. All we have to do is keep track of the last ID we saw, then filter the results so we only fetch rows we haven’t seen.
Read more [mattallan.me]
Introducting the Tappable trait to use 'tap' with any class
Recently Laravel introduced a Tappable trait. This blogpost explains what this trait allows you to do.
As you might know, the Laravel framework comes with a handy tap method which allows you to call the given closure with the given value and then return the value. Sounds confusing? It probably is until you've seen it!
Read more [protone.media]
SOLID, interfaces and final
My colleague Brent started a new podcasts series called "Rant with Brent". In the first episode has explains why he likes the "final" keyword in PHP.
I'm giving podcasting a try. Let me know what you think of it via Twitter or e-mail. You can download the episode here. In this episode I talk about why I think final helps you write better maintainable code.
Read more [stitcher.io]
Testing Streamed Responses in Laravel
Over at Laravel News, Paul Redmond published a good way to test streamed responses.
Read more [laravel-news.com]
Short closures in PHP
Short closures are coming to PHP 7.4. In this blogpost, my colleague Brent exaplins what they look like and how they can be used
Short closures, also called arrow functions, are a way of writing shorter functions in PHP. This notation is useful when passing closures to functions like array_map or array_filter.
Read more [stitcher.io]
Execute Eloquent methods without firing events
A little helper method I put on my base Model class on Secret Project VI… Kinda handy. ?♂️ pic.twitter.com/mPOMV73d5L
— Taylor Otwell ? (@taylorotwell) April 30, 2019
Read more [twitter.com]
New in PHP 7.4
Brent lists the goodies coming to PHP 7.4, which will be released in december. This is going to be an epic release!
Read more [stitcher.io]
A small trait to run use progression bars in Artisan commands
???
— Jeff Ochoa (@Jeffer_8a) April 24, 2019
A small trait to run use progression bars in @laravelphp commands#Laravel #PHP pic.twitter.com/lvGylb5QXm
Read more [twitter.com]
Implementing event sourcing: improving the developer experience original
Recently we've released v2 of laravel-event-projector. The package is probably the easiest way to get started with event sourcing in Laravel. In v2 we've introduced two "invisible" features that improve the developer experience: auto-detection of event handling methods and auto-discovery of event handlers.