Forem

Php Profi
Php Profi

Posted on • Originally published at phpprofi.ru on

4 1

Жадная загрузка в Laravel: load() или with()?

Прим. пер.: Это небольшая заметка о работе методов ::with() и ::load() Laravel Eloquent-а, которую должен знать каждый разработчик, пишущий на Laravel. Тут ничего нового, но, как оказывается, не все об этом знают.

Сегодня, работая с одним из моих проектов (который написан на фреймворке laravel) я столкнулся с ситуацией, когда мне нужно для одной из моделей получить данные по другим моделям, связанные с этой. Так вот, для этого у меня есть два варианта, предоставляемых Laravel-ом, которые обычно называют жадной загрузкой:

Оба метода достигают тех же конечных результатов — жадной загрузки моделей в первую. На самом деле, они оба запускают одни и те же два запроса. Какой выбрать?

Читать далее: http://phpprofi.ru/blogs/post/71

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay