如何在 Laravel 5 中获取具有 where 条件的数据列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31707514/
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
How to get list of data with where condition in Laravel 5
提问by jzon
I want to get REST url to retrieve data where name="hello" and category="main"
我想获取 REST url 来检索 name="hello" 和 category="main" 的数据
This is my Model
这是我的模型
public function show($name, $category)
{
$FodMap = FodMap::find($name, $category);
return $FodMap;
}
Routes
路线
Route::get('FodMap/{name}/{category}', 'FodMapController@show');
What I want is when I type localhost/api/FodMap/hello/main
我想要的是我打字的时候 localhost/api/FodMap/hello/main
All result should display which matches with hello and main
所有结果都应显示与 hello 和 main 匹配的结果
Please advise me to proceed.... I'm new to Laravel.
请建议我继续......我是 Laravel 的新手。
回答by Arthur Samarcos
The eloquent query is something like this:
雄辩的查询是这样的:
FodMap::where('name','=',$name)->where('category','=',$category)->get()
That will return an Eloquent Collection instance.
这将返回一个 Eloquent Collection 实例。