I have a table with products, and another table with movements of products (addition, substraction) and table of authors of these movements. I want to get all products with the last movement in Eloquent ORM I have tried...
$products = Product::with( array
(
'movs' => function ( $query )
{
$query->orderBy( 'id', 'dsc' )->with('author')->first();
}
) )->get();
But only get a zeroed movs array.
But when I do
$products = Product::with( array
(
'movs' => function ( $query )
{
$query->orderBy( 'id', 'dsc' )->with('author');
}
) )->get();
I get all the according related models (movs and authors)... Is there any way to get this in Eloquent or I have to do with query builder... if so... how?
Thanks you in advance.