my route:

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

my function:

public function show($key_id_fk)
{
    $sub=DefintionDetails::find($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

3
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.

0
Sunil Kashyap On

You are setting key_id_fk as http://example.com/page/1 in route and passing parameter as http://example.com/page?key_id_fk=1 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 http://example.com/page/1 format or change getting method in the controller to public function show(Request $request) and $request->key_id_fk

0
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
    $sub=DefintionDetails::find($request->query('key_id_fk')); 

    // the rest of your code
}

Try

http://localhost/page?key_id_fk=1

Laravel Requests

0
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); 

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

Your postman route:

http://example.com/page/1