EagerLoadingでLaravelのN+1問題を解決するテクニック - Qiita

はじめに LaravelでEloquent ORMを使っていると、知らず知らずのうちに N+1クエリ問題 に陥ることがあります。 本記事では、この問題を根本から解決する Eager Loading(イーガーローディング) というテクニックをわかりやすく解説します。 1....

Qiita

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.

#Laravel #Eloquent #PHP

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

Eloquent Guard: как ловить N+1 и медленные запросы в Laravel, не зарываясь в vendor

Проблема N+1 стара как мир. Инструментов много: Debugbar хорош локально, Telescope тяжеловат для продакшена. Мне хотелось решения, которое будет «стучать» в Slack или Telegram именно тогда, когда...

Хабр

Обновлена статья о коллекциях Laravel:

Узнайте, как использовать Коллекции Laravel для фильтрации, преобразования и оптимизации работы с данными. От основ (filter, map) до продвинутых техник: ленивые коллекции, макросы и операции сведения.

https://www.dev-notes.ru/articles/laravel/collections/

#Laravel #Collection #Eloquent #PHP

Laravel Коллекции от А до Я: Фильтрация, Lazy Collections и макросы

Хватит писать циклы! Узнайте, как использовать Коллекции Laravel для фильтрации, трансформации и обработки миллионов записей без утечек памяти.

Заметки разработчика

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.

#Laravel #Eloquent

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);

#laravel #eloquent

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?

#Laravel #Eloquent #PHP

Eloquent: Getting Started - Laravel 12.x - The PHP Framework For Web Artisans

Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.

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

#databases #performance #firefox #eloquent #mariadb #charm

Taming Firefox’s places.sqlite: A Weekend Performance Breakthrough

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.

R-Digital