如何获取Laravel 5中where条件的数据列表

时间:2015-07-29 17:43:20

标签: php laravel laravel-5 laravel-5.1

我想让REST url检索name =“hello”和category =“main”的数据

这是我的模特

public function show($name, $category)
    {
        $FodMap = FodMap::find($name, $category);
        return $FodMap;


    }

路线

Route::get('FodMap/{name}/{category}', 'FodMapController@show');

当我输入localhost/api/FodMap/hello/main

时,我想要的是什么

所有结果应显示与hello和main

匹配的内容

请告诉我继续......我是Laravel的新手。

2 个答案:

答案 0 :(得分:2)

雄辩的查询是这样的:

FodMap::where('name','=',$name)->where('category','=',$category)->get()

这将返回一个Eloquent Collection实例。

答案 1 :(得分:0)

public function getAllData()
{
    $data = tableName::where('Method','Delivery')->get();
    return response()->json($data, 200);
}

$users = DB::table_Name('users')->select('name', 'email as user_email')->get();

$users = DB::table('users')
                    ->whereIn('id', [1, 2, 3])
                    ->get();
相关问题