EagerLoadingでLaravelのN+1問題を解決するテクニック
https://qiita.com/Fukuda_Genee/items/6ff6bf3c378779dd217f?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items
EagerLoadingでLaravelのN+1問題を解決するテクニック
https://qiita.com/Fukuda_Genee/items/6ff6bf3c378779dd217f?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items
Eloquent relationships — let AI get them right every time. 🧠
Describe your data structure in plain English:
"User has many Posts. Post belongs to User and has many Comments. Comment belongs to Post and User."
LaraCopilot generates:
→ All three models with correct method types
→ All foreign keys in migrations
→ Eager loading in controllers
Describe it. Get it right. First time.
Eloquent Guard: как ловить N+1 и медленные запросы в Laravel, не зарываясь в vendor
Проблема N+1 стара как мир. Инструментов много: Debugbar хорош локально, Telescope тяжеловат для продакшена. Мне хотелось решения, которое будет «стучать» в Slack или Telegram именно тогда, когда проблема случилась на проде, и при этом сразу показывать пальцем на виновную строку кода.
https://habr.com/ru/articles/1010822/
#laravel #eloquent #php #sql #mysql #postgresql #database_optimization #database_performance #database_monitoring
Обновлена статья о коллекциях Laravel:
Узнайте, как использовать Коллекции Laravel для фильтрации, преобразования и оптимизации работы с данными. От основ (filter, map) до продвинутых техник: ленивые коллекции, макросы и операции сведения.
Uff, I've been bit by a quirky Eloquent issue. The worse part is that I know why it happens but I don't know how to "fix it" (I've found a workaround, but Id like to prevent it from happening in the future, ideally with a patch upstream).
It involves relationships, macros for the Builder and eloquent silently overriding an `id` column because the results from the SQL query contain 2 different `id` columns (because of a join).
I'll try to create a sample project with minimum code to reproduce and see if I can manage a fix.
Doctor reveals the 1-minute daily hack that can radically improve public speaking skills
https://fed.brid.gy/r/https://www.upworthy.com/how-to-get-better-at-public-speaking
A great option to optimize database writes in Laravel is using bulk operations.
E.g. "upsert()" can insert/update multiple rows with _one_ query using "on duplicate" logic:
User::upsert(values: [
['email' => 'foo@domain', 'name' => 'Foo'],
['email' => 'bar@domain', 'name' => 'Bar'],
], uniqueBy: ['email'], update: ['name']);
becomes:
INSERT INTO users (email, name),
VALUES
('foo@example', 'Foo'),
('bar@example', 'Bar')
ON DUPLICATE KEY UPDATE name = values(name);
When adding the type for the Query Builder that's passed as an argument to an Eloquent's scope, do you use `Illuminate\Database\Eloquent\Builder` or `Illuminate\Contracts\Database\Eloquent\Builder`.
I just realized they were being used interchangeably on a project I've been working on.
My initial thought would be to use always the contract (the interface is implemented by `Eloquent\Builder` and by `Eloquent/Relations/Relation`), but looking at the docs, the official stance is to import the Builder object 🤔
https://laravel.com/docs/12.x/eloquent#local-scopes
Any thoughts?
Turned a weekend hack into a 1000× speedup: importing Firefox’s places.sqlite went from 4h ➝ 10s. 300k+ rows, clean architecture, future-ready stats. Full story here: https://reifschneider.digital/blog/taming-sqlite
A bored-weekend side project turned into a tiny masterclass in database design. I rebuilt a “works-for-now” importer into a set-based, transactional loader and dropped runtime from 4 hours to under 10 seconds for 300k+ rows – on an average NVMe host with MariaDB. Same machine, same data, different architecture. Here’s the story, the thinking, and just enough code.