简体   繁体   English

Laravel-Lumen获取带有参数的请求不起作用

[英]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 这是我的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 !!?? 如果我从路由和控制器中删除该参数,则它正常工作,并且我在同一设备上有另一个Lumen项目,其所有工作都正常!

Im on mac and apache 我在Mac和Apache上

Any help will be much appreciated 任何帮助都感激不尽

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. 注意{province}区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM