php - 404 not found : laravel api with parameter

Call to Laravel API with parameter gets an error of 404: page not found, But while removing the parameter It works fine.

API.php have the following code

Route::get('Parties/{aToken}',"CustomerController@apiParties");

The controller has the following Code

function apiParties(request $request,$token){
    $parties = DB::table('parties')
                ->Where("status","1")
                ->get()
                ->take(20);
    return json_encode($parties);
}

Tried too many things but not working. I'm working on the server, not in localhost so don't have a terminal.

Answer

Solution:

Change this

->get()->take(20);

to

->take(20)->get();

more fluently :

return DB::table('parties')
            ->Where("status","1")
            ->take(20)
            ->toJson();

Only use Request when you need it, i see that you not really use it on this scope of code. And make sure you already import DB Facades correctly :

use Illuminate\Support\Facades\DB;

Answer

Solution:

If you want to make the parameter optional then add ? before the close brace.

Second thing is that you need to use Request $request starting with capital letter.

Answer

Solution:

Always use small letters in the URLs and for the parameters.

Also, the parameter in the controller method should be Request instead of request.

Source