Eloquent's query builder has a whereBetween function
? TIL Eloquent's query builder has a whereBetween function#laravel #php pic.twitter.com/SyCXshL3Oe
— Freek Van der Herten (@freekmurze) November 5, 2017
Read more [twitter.com]
Posts tagged with eloquent
? TIL Eloquent's query builder has a whereBetween function#laravel #php pic.twitter.com/SyCXshL3Oe
— Freek Van der Herten (@freekmurze) November 5, 2017
Read more [twitter.com]
Nice hidden @laravelphp Eloquent feature: you can specify the columns to eager load directly in the 'with' call! pic.twitter.com/vQT8CaRqGC
— Stidges (@stidges) September 13, 2017
Read more [twitter.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."
Caleb Porzio, co-presenter of the Twenty Percent Time podcast, published a new article on the Tightenco blog. This time he guides us through a nice use case for extending Eloquent models.
Let’s explore another alternative that can be used as a stand-in for repetitive where statements and local scopes. This technique involves creating new Eloquent models that extend other models. By extending another model, you inherit the full functionality of the parent model, while retaining the ability to add custom methods, scopes, event listeners, etc. This is commonly referred to as “Single Table Inheritance,” but I prefer to just call it “Model Inheritance”.
Cool little Laravel 5.5 Eloquent Collection macro to assert two model collections are the same ?? pic.twitter.com/zzbkr1fL9T
— Adam Wathan (@adamwathan) June 14, 2017
Read more [twitter.com]
Jarek Tkaczyk demonstrates how you can use a helper relation to eager load specific models.
Have you ever needed to show only single related model from the hasMany relationship on a set of parents?Being it latest, highest or just random, it’s not very clever to load whole collection using eager loading, just like running query per every parent.
Of course you can do that better, and now let me show you how.
https://softonsofa.com/tweaking-eloquent-relations-how-to-get-latest-related-model/
Jarek Tkaczyk wrote a blogpost on the usage of accessors in Eloquent. He demonstrates what could go wrong when using accessors on certain fields.
The moral of the story is, that data handling and its presentation should not go into the same bucket. And the model is that bucket – instead of creating accessors, traits or god knows what for this task, better use decorator (like) pattern where you can do all the necessary work for preparing your data to be displayed in your view, without touching actual values anywhere else.
https://softonsofa.com/they-can-bite-how-not-to-use-accessors-in-eloquent/
Keep this in mind when you should use my pragmatic approach for presenters. Watch out for conflicting names.
Over at the excellent dotdev.co Amo Chohan wrote an article on how to structure code when you need many filters on an Eloquent model.
I recently needed to implement a search feature in an events management project I was building. What begun as a few simple options (searching by name, e-mail etc), turned into a pretty large set of parameters. Today, I’ll go over the process I went through and how I built a flexible and scalable search system. For those of you who are eager to see the final code, head over to the Git repository to see the code.
https://dotdev.co/writing-advanced-eloquent-search-query-filters-de8b6c2598db
This is a technique that I recently found useful. Eloquent models allow you to specify a custom collection object to be returned – which sometimes can be a great place to put some business logic.https://michaelstivala.com/pushing-logic-custom-collections/
Eric Barnes, the curator of Laravel News, recently decided to publish guest posts. Mike Bronner contributed the first guest post on how to install Z-Ray in Homestead. Today, an article written by me was published.
One of the really great things about ORM’s that implement the Active Recordpattern like Eloquent is, they are really easy and really intuitive to use.http://culttt.com/2014/07/07/doctrine-2-different-eloquent/With Active Record, you basically just have an object that you can manipulate and then save. Calling
save()on the object updates the database, and all of the magic persistence happens behind the scenes.Having the business logic of the object and the persistence logic of the database tied together definitely makes working with an Active Record ORM easier to pick up.
In this tutorial I want to explore exactly how Doctrine 2, an ORM that implements the Data Mapper pattern, is different to Eloquent.