Magic where methods on Laravel's query builder
Surprised no one knew about that, but did you know you can do this? pic.twitter.com/OfJ7udnHFe
— Mohamed Said? (@themsaid) 15 augustus 2018
Surprised no one knew about that, but did you know you can do this? pic.twitter.com/OfJ7udnHFe
— Mohamed Said? (@themsaid) 15 augustus 2018
The people at Kinsta published a nice overview of all changes coming to PHP 7.3 which will be released in December.
In this post, we’ll provide an overview of the features and changes that we personally consider most relevant. But you can always check the full list of features, changes and bug fixes in PHP 7.3 upgrade notes and PHP 7.3 Requests For Comments.
Read more [kinsta.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.
"Always fresh, useful tips and articles. Carefully selected community content. My favorite newsletter, which I look forward to every time."
Nick Basile, UX instructor at Lambda school, write a good practical tutorial on creating custom Nova actions.
In my last post, we started building a simple CRM using Laravel Nova. It was pretty complete when we left it, but I think we can add a few more features and explore the rest of what Nova has to offer. In this walkthrough, we'll take a look at how to use Nova's Actions and authorization.
Read more [nick-basile.com]
My colleague Brent explains how you can easily work with MySQL views in Laravel.
MySQL views are a way of storing queries on the database level, and producing virtual tables with them. In this post we'll look at why you want to use them and how they can be integrated in Laravel with Eloquent models.
Read more [stitcher.io]
How about this? pic.twitter.com/JkKVBgfOtZ
— Dave Yoakum (@dawiyo) 1 August 2018
You can even write it shorter as User::latest()->value('name');
Read more [twitter.com]
Marcel Pociot, serial open source creator, released another cool Laravel package.
When your Laravel project grows, so do the Laravel views. Sometimes it might be hard to figure out, which part of the output HTML was rendered using which template. With this package, you can take a peek into your Laravel views and find out which template is responsible for which part of the output HTML.
Read more [github.com]
In another cool blogpost, Matthias Noback explains a few best practices around newing up objects, illustrated with some great examples.
Consider the following rule: "When you create an object, it should be complete, consistent and valid in one go." It is derived from the more general principle that it should not be possible for an object to exist in an inconsistent state. I think this is a very important rule, one that will gradually lead everyone from the swamps of those dreaded "anemic" domain models. However, the question still remains: what does all of this mean?
Read more [matthiasnoback.nl]
? Tip: the `abort` helper in @laravelphp can take any `Response` object!
— Joseph Silber (@joseph_silber) 19 juli 2018
Especially useful for redirection, since the `redirect` & `back` helpers only work in top-level controller methods.
When in a supporting method from which you can't `return`, use the `abort` helper ? pic.twitter.com/dFwhhXz211
Read more [twitter.com]
In most applications you store the state of the application in the database. If something needs to change you simply update values in a table. When using event sourcing you'll take a different approach. All changes to application state are stored as a series of events. The key benefit is that you…
A lesser-known @laravelphp feature: You can define your IDE/editor in your config/app.php file to let the Whoops error handler allow you to open files directly from within the error message. pic.twitter.com/My0BUjTIrM
— Marcel Pociot (@marcelpociot) 10 juli 2018
Read more [twitter.com]
Larry Garfield, director of developer experience at Platform.sh, published some interesting numbers on arrays vs classes.
The first thing we can conclude is that if the one and only thing you care about is serialization/deserialization performance, associative arrays still win. They're the most time efficient by more than 50%, and the most space efficient by up to 20%. The second thing we can conclude is that stdClass should be used basically never. It's slower and more memory intensive than arrays in every circumstance. Just don't go there.
Read more [steemit.com]
In an older post on his blog Mohammed Said, Laravel Employee #1, shares a cool trick on how to avoid having to create an event listener.
Instead of having to create a class for the listener and another for the notification/mailable, wouldn't it be cool if we can register the Notification/Mailable as an event listener? ... While some may consider this an anti-SRP hack I think it's a pretty neat implementation that you can use in your application to prevent creating an extra listener class, your call :)
Read more [themsaid.com]
Andrew Schmelyun collected some cool Eloquent niceties.
Over the last year or so, I’ve been collecting and (sometimes) tweeting about methods and helpers I’ve stumbled across in Laravel’s Eloquent ORM. Most of these aren’t that obvious in the documentation, but have made a huge impact as my applications have grown in both size and complexity.
Read more [medium.com]
?? Who knew, Laravel's string helper class can generate uuids - woot!
— Caleb Porzio (@calebporzio) July 5, 2018
If you care, here's my UUID model trait I use (the packages are too heavy handed for me) https://t.co/L8Il1sH5VA pic.twitter.com/K6OwkHKQBD
Read more [twitter.com]
Marcel Pociot created another great package. laravel-dump-server will transmit all output of dump calls to another port on your system. This will avoid cluttering up the responses of your app with debug output. Here's a gif taken from the readme of the package:
https://github.com/beyondcode/laravel-dump-server
The last few months I've been working on a package called laravel-event-projector. This package aims to be a simple and very pragmatic way to get started with event sourcing in Laravel. Ahead of it's release, which will happen in a few days, I've recorded a small video introduction. You can find the…
?♂️⏲️ Just found all these handy class constants in Carbon - woohoo! ? pic.twitter.com/pL0HeKGVx4
— Caleb Porzio (@calebporzio) 29 juni 2018
Read more [twitter.com]
Joseph Silber, a very active Laravel contributor, has written a new blogpost on morph maps, a feature to decouple your database from your model class names.
Polymorphic relations let you set up a relationship between many different model types, without the need for extra tables. This works by storing the "morphable type" (explained below) in the database, in addition to the morphable type's ID. By default, the morphable type stored in the database is the model's full class name. While this works, it tightly couples your database to your PHP application. Let's look at how we can instruct Eloquent to use more generic values for these morphable types.
Read more [josephsilber.com]
I often use Eloquent's `query` just to have the code better aligned#visualdebtisreal pic.twitter.com/0JWrzx6wEN
— Freek Van der Herten (@freekmurze) 2 juli 2018
Read more [twitter.com]
Mark Baker, serial conference speaker and creator of the PhpSpreadsheet package shares some thoughts on how to create private classes using anonymous classes.
I’ve written before about the benefits of using PHP’s Anonymous Classes for test doubles; but Anonymous Classes also have potential usecases within production code as well. In this article I’m going to describe one such usecase that can be particularly useful within libraries, and that is replicating the access of Package Private (in Java), or Protected Internal Classes (as per C#).
Read more [markbakeruk.net]