让我返回了这个json作为Laravel的响应:
Route::get('/data', function(){
$drivers = Driver::select('driver_number','first_name','ph_number')
->where('driver_number',$request->get('driver_number'))
->get();
return response()->json($drivers);
});
以上返回此json:
[
{
"driver_number": "Dr_01",
"first_name": "jimale",
"ph_number": 4253226
},
{
"driver_number": "Dr_02",
"first_name": "mawlid",
"ph_number": 4222321
},
{
"driver_number": "Dr_03",
"first_name": "yusuf",
"ph_number": 3624222
},
{
"driver_number": "Dr_04",
"first_name": "yaxye",
"ph_number": 343243
}
]
因此,我想接收一个json对象,其中driver_number
= Dr_02
...出于这个原因,我使用 POSTMAN 来做到这一点,我这样说:
但是这将显示所有JSON数组,而不是我的特定json对象。 有谁知道我想念的地方吗?谢谢
答案 0 :(得分:2)
使用where子句编写过滤查询,如下所示:
public function index(Request $request){
$drivers = Driver::select('driver_number','first_name','ph_number')->where('driver_number',$request->get('driver_number'))->get();
}