my route:

Route::get('page/{key_id_fk}', '[email protected]'); 

my function:

public function show($key_id_fk)

  //  $main=Definition::where([['type','=',1],['available','=',1],['id_definition','=',$sub->id_def]])->get();
    return response()->json($sub , 200);

on post man route is page?key_id_fk=1 give error 404 not found key in data base but didn't read.

4 Answers

thisiskelvin On

You should be accessing page/1 rather than page?key_id_fk=1 as you are not using parameter queries in your request url.

Your route format is page/$key_id_fk.

Sunil Kashyap On

You are setting key_id_fk as in route and passing parameter as difference is first one is URL route data and second is GET parameter data to get data from URL route you have this public function show($key_id_fk) and to get data from GET parameter public function show(Request $request) and $request->key_id_fk.

so change URL to this format or change getting method in the controller to public function show(Request $request) and $request->key_id_fk

Leonardo On

In your Controller

Route::get('page', '[email protected]');

Catch your query string using Laravel Request

public function show(Request $request){

    //check if key_id_value is present in your request
    if ($request->has('key_id_fk')) {

    //get the value of your query string

    // the rest of your code



Laravel Requests

Natvarsinh Parmar - bapu On

In the route file:

    Route::get('page/{key_id_fk}', '[email protected]'); 

In the controller:

public function show($key_id_fk){

    $sub = DefintionDetails::find($key_id_fk); 

       return response()->json(['success' => true, 'sub' => $sub]);
    } else {
       return response()->json(['success' => false, 'error_message' => 'No data found!']);

Your postman route: