fetch n records
Modelo::where('llave', '>', $var)->take($n)->get();
it fails because it does not know which records to bring it is missing
latest()
Modelo::all()->take($n);
The same thing happens to this query as the one above is missing the lastest argument
Records between a and b
Modelo::whereIn('campo',[$a,$b])->take($n)->get();
This query should return the fields that are between a and b but it only returns those that match a and b
The queries, even though the parameters are already predefined, are variables for my API. Only when I try to run these queries it fails.
You mention that in both cases you must include the method
latest()
, so I would rearrange your query like this:first consultation
second consultation
In the case of the second query, you cannot use
take()
the method at the same time,all()
so I suggest you use the methodselect()
to indicate which columns you want it to bring you; if you want all the columns you can do it like thisthird consultation
You pass the method
latest
as an argument; the name of the column by which you want to be sortedDESC
and it should return the results