php - laravel 5.5 缺少 [Route : 所需的参数

标签 php mysql laravel eloquent laravel-5.5

路由文件:-

Route::get('/Observation/{type}/list/{status}', 'ObservationController@index')->name('list_observation');

当前网址: localhost:8088/hse/public/Observation/status/list/2

Controller :

protected $type ;
    protected $status ;
    public function __construct(Request $request)
    {
        $this->middleware('auth')->except('getBuildings');
        $this->status = Route::current()->parameter('status');
        $this->type = Route::current()->parameter('type');
    }

    public function index()
    {
        if ($this->status == 'all'){
        $observations = Observation::all();
        }
        else {
            $observations = Observation::where($this->Type(),$this->status)->get();
        }
       return view('observations._list')->with('observations',$observations);
    }
    public function Type(){
        switch ($this->type){
            case 'building':
                $this->type = 'building_id';
                break;
            case 'status':
                $this->type = 'status_id';
                break;
        }
        return $this->type;


    }

错误显示: [路线:list_observation] [URI:Observation/{type}/list/{status}] 缺少必需的参数。 ( View :

当我删除查询行中的 $this->Type() 方法时,错误消失。

$this->Type() 方法的返回值是: status_id

哪个是正确的数据库列名。

最佳答案

也许在 view 的某处或者您生成该 URL 的地方您没有将所有必需的参数传递给路由。

关于php - laravel 5.5 缺少 [Route : 所需的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47191141/

相关文章:

php - 特质; PHP 5.4 中的 parent 和 self 类型提示

PHP 命名空间 - 更上一层楼?

两个 UNIQUE KEY 上的 MySQL CONSTRAINT,它们使用相同的 FOREIGN KEY ID

mysql - 同表带条件内连接

laravel - Composer 自动加载器找不到类

php - 对 api token 使用 Config 会出现错误 'URI must be a string or UriInterface' Laravel

php - 使用 fetch(PDO::FETCH_ASSOC) 循环查询结果

mysql - Laravel 5.5 - 迁移不起作用

php - laravel Pusher - 在生产中发送事件不起作用

php - 有没有办法使用 Laravel 查找数据库中特定表的最后更新时间?