Laravel Eloquent how to get the second or third record?

$order->products()->skip(1)->first();//Second row
$order->products()->skip(2)->first();//Third row
....

Is more performant than loading all products and getting only first, second, ecc..


Instead if you want both second and third, you can get only them in a single query without load other rows, with similar approach:

$order->products()->skip(1)->take(2)->get(); //Skip first, take second and third

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)