laravel 调用未定义的方法 Illuminate\Database\Query\Builder
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22463968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined method Illuminate\Database\Query\Builder
提问by Brightside
I am new to laravel 4 and keep getting the same error trying to learn about some methods in DB class.
我是 laravel 4 的新手,并且在尝试了解 DB 类中的某些方法时不断遇到相同的错误。
Call to undefined method Illuminate\Database\Query\Builder
I get same erros trying to use "->or_where", "->order_by".
我在尝试使用“->or_where”、“->order_by”时遇到了同样的错误。
another problem is parsing the dynamic methods:
另一个问题是解析动态方法:
->where_name("test")
turns into
变成
`users` where `_name` = test)
but if i try to do
但如果我尝试做
->wherename("test")
then everything is fine.
那么一切都很好。
回答by Mariano Córdoba
You're using an incorrect syntax for orWhere
and orderBy
.
您对orWhere
and使用了错误的语法orderBy
。
This is the correct syntax for orWhere
:
这是正确的语法orWhere
:
DB::table('users')
->where('name', '=', 'John')
->orWhere(function($query)
{
$query->where('votes', '>', 100)
->where('title', '<>', 'Admin');
})
->get();
And this for orderBy
:
这对于orderBy
:
$users = DB::table('users')
->orderBy('name', 'desc')
->get();
回答by Antonio Carlos Ribeiro
All methods in Laravel 3 have changed from snake case
Laravel 3 中的所有方法都从蛇案例改变了
->where_name("test")
to camel case in Laravel 4
Laravel 4 中的骆驼案例
->whereName("test")