0

let's just I have returned this json as response from 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);
});

the above returns this 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
}
]

So, I wanted to receive a single json object where driver_number= Dr_02... for that reason i used POSTMAN to do that and i said like this:

http://localhost/BSProject/public/data?driver_number=Dr_02

BUT this is displaying all JSON Array instead of my specific json object. Do any one knows where i missed? thanks

1 Answer 1

2

write your filter query with where clause like this :

public function index(Request $request){
    $drivers = Driver::select('driver_number','first_name','ph_number')->where('driver_number',$request->get('driver_number'))->get();
}
Sign up to request clarification or add additional context in comments.

3 Comments

where does that request is coming from, i dont have it in my code
thanks dude, that's my bad didn't notice sending request to get the target json
@AhmedAtoui,@MaiRich The actual problem was the dependency injection Route::get('/data', function(Request $request) $request is undefined in the first example! You meant to use request(), the global helper function :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.