简体   繁体   English

LARAVEL 调用未定义的方法 Illuminate\\Database\\Eloquent\\Builder::splice()

[英]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?有谁知道为什么或如何?

Many thanks in advance!提前谢谢了! 代码

$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您需要了解您正在使用的类,尤其是BuilderCollection

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.

相关问题 Laravel 分页 - 调用未定义的方法 Illuminate\\Database\\Eloquent\\Builder::links() - Laravel Pagination - Call to undefined method Illuminate\Database\Eloquent\Builder::links() Laravel 7.6 调用未定义的方法 Illuminate\Database\Eloquent\Builder::appends() - Laravel 7.6 Call to undefined method Illuminate\Database\Eloquent\Builder::appends() 调用未定义的方法 Illuminate\Database\Eloquent\Builder::filter() - Call to undefined method Illuminate\Database\Eloquent\Builder::filter() 使用 laravel scout 和 tntsearch 调用未定义的方法 Illuminate\Database\Eloquent\Builder::search() - Call to undefined method Illuminate\Database\Eloquent\Builder::search() using laravel scout and tntsearch 调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Builder :: save() - Call to undefined method Illuminate\Database\Eloquent\Builder::save() Laravel:调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: where() - Laravel: Call to undefined method Illuminate\Database\Eloquent\Collection::where() Laravel 5 - 调用未定义的方法 Illuminate\Database\Eloquent\Collection::Paginate() - Laravel 5 - Call to undefined method Illuminate\Database\Eloquent\Collection::Paginate() 调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: save()laravel - Call to undefined method Illuminate\Database\Eloquent\Collection::save() laravel 调用未定义的方法 Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::type() [Laravel] - Call to undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::type() [Laravel] Laravel 5:调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: exists() - Laravel 5: Call to undefined method Illuminate\Database\Eloquent\Collection::exists()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM