[英]LARAVEL Call to undefined method Illuminate\Database\Eloquent\Builder::splice()
I am trying to select some atributes of the table Animals and at the same time selecting their photos.我正在尝试选择表 Animals 的一些属性,同时选择他们的照片。
The problem is that in my case I want to select 20 animals depending on the page (For example, if I am in page 2 I want to take the animals between 20-40问题是,在我的情况下,我想根据页面选择 20 只动物(例如,如果我在第 2 页,我想在 20-40
I am doing an splice for that, but I don't know how to make it work, it throws me that error.我正在为此进行拼接,但我不知道如何使其工作,它向我抛出了那个错误。
Anyobody knows why or how?有谁知道为什么或如何?
$cantidad is the quantity of animals I want to take $pagina is the page $cantidad 是我想带的动物数量 $pagina 是页面
You need to be aware of the class you're working with, especially Builder
vs Collection
您需要了解您正在使用的类,尤其是Builder
与Collection
All queries in Laravel ( Animal::select(...)
) are instances of the Builder
class until a closure ( ->get()
, ->first()
, etc) is called. Laravel 中的所有查询( Animal::select(...)
)都是Builder
类的实例,直到调用闭包( ->get()
、 ->first()
等)。 Since you're not using one of those closures before calling ->splice()
, you're attempting to call this method on a class ( Builder
) that doesn't have it.由于您在调用->splice()
之前没有使用这些闭包之一,因此您试图在没有它的类( Builder
)上调用此方法。 The Collection
class has this method: Collection
类有这个方法:
https://laravel.com/docs/7.x/collections#method-splice https://laravel.com/docs/7.x/collections#method-splice
So you need to use ->get()
before ->splice()
:所以你需要在->splice()
之前使用->get()
->splice()
:
return Animal::select(...)
->join(...)
->where(...)
->get()
->splice(...)
->toJson();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.