Документация говорит (судя как я понял по переводу)
https://laravel.com/docs/5.2/eloquent-relationships
Что количество запросов уменьшается в десятки раз если использовать метод
with:
Thankfully, we can use eager loading to reduce this operation to just 2 queries. When querying, you may specify which relationships should be eager loaded using the with method:
----------
Но в моем примере:
$adboard = Board::with('user', 'category', 'currency', 'getPhoto')->orderBy('created_at','desc')->paginate(15);
Что так 8 запросов с методом
with:
select count(*) as aggregate from `boards` 270μs
select * from `boards` order by `created_at` desc limit 15 offset 0 520μs
select * from `users` where `users`.`id` in ('2') 470μs
select * from `board_categories` where `board_categories`.`id` in ('4') 270μs
select * from `board_currencies` where `board_currencies`.`id` in ('1') 250μs
select * from `files` where `files`.`id` in ('12') 270μs
select * from `board_categories` 240μs
select * from `board_currencies`
Что так, без
with:
$adboard = Board::orderBy('created_at','desc')->paginate(15);
select count(*) as aggregate from `boards` 260μs
select * from `boards` order by `created_at` desc limit 15 offset 0 310μs
select * from `board_categories` 240μs
select * from `board_currencies` 220μs
select * from `files` where `files`.`id` = '12' limit 1 380μs
select * from `board_categories` where `board_categories`.`id` = '4' limit 1 230μs
select * from `board_currencies` where `board_currencies`.`id` = '1' limit 1 220μs
select * from `users` where `users`.`id` = '2' limit 1
Или я не так понял и не то делаю?