Mohammed Riyadh
Mohammed Riyadh

Reputation: 1019

Laravel-Lumen get request with parameter doesn't work

I'm facing a strange issue with lumen, all post and get request are working fine but only the get requests with parameter is not with below error

NotFoundHttpException

in RoutesRequests.php line 229

at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
in RoutesRequests.php line 416

Here is my Web.php

$router->get('/', function () use ($router) {
    return $router->app->version();
});


$router->group(['prefix' => 'api'], function () use ($router) {
    $router->post('login','UserController@login');
    $router->post('signup','UserController@signup');
    $router->patch('profile','UserController@update');
    $router->post('verfiy','UserController@verfiy');
    $router->post('order','OrderController@store');
    $router->get('userorders/{$uid}','OrderController@userOrder');
    $router->get('locations/{$province}','LocationController@list');
    $router->get('offers/{$province}','OfferController@list');


});

And this is my controller

<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use App\Offer;


class OfferController extends Controller
{




    public function list($province)
    {
        $offers = Offer::where('province',$province)
                        ->orderBy('num_orders', 'desc')
                        ->paginate(20);
        return response()->json(['status_code'=>1000,'data'=>$offers , 'message'=>null],200);
    }




}

If i remove the parameter from the route and the controller it works and I have another Lumen project on same device and its works all fine with all requests !!??

Im on mac and apache

Any help will be much appreciated

Upvotes: 0

Views: 1576

Answers (1)

Flame
Flame

Reputation: 7580

You should define a route like:

$router->get('offers/{province}','OfferController@list');

and not like:

$router->get('offers/{$province}','OfferController@list');

Note the {province} difference.

Upvotes: 1

Related Questions