简体   繁体   English

缺少路线参数-参数已传递给route()方法

[英]Missing route parameter - param was passed to route() method

I am having trouble with routing in Laravel 5.4. 我在Laravel 5.4中进行路由遇到麻烦。 I am trying to display a simple edit form for a company. 我正在尝试为公司显示一个简单的编辑表单。

The error I'm getting is 我得到的错误是

在此处输入图片说明

web.php: web.php:

$this->get('company/edit/{company}','SuperAdmin\CompanyController@showEditForm')->name('company.edit');
$this->post('company/edit', 'SuperAdmin\CompanyController@edit');

How I build link to the route: 我如何建立到路线的链接:

<a href="{{route('company.edit', ['company' => $company->id])}}" class="btn btn-success">Edit</a>

In the controller: 在控制器中:

public function showEditForm()
{
    return view('super.company.edit');
}

SOLVED: Dear god, I've forgot to add the parameter to the route() method in the view where I render the form. 求助:亲爱的上帝,我忘记了在渲染表单的视图中将参数添加到route()方法中。 Thanks everyone. 感谢大家。

You do not need to define the key for the route variable just pass it as a second argument in the route function. 您无需为route变量定义键,只需将其作为第二个参数传递给route函数即可。 Laravel will automatically resolve the parameter in the order. Laravel将自动按顺序解析参数。

Like: 喜欢:

route('company.edit',  $company->id);

Hope it would help. 希望这会有所帮助。

First of all you can debug the id like dd($company->id) to make sure you are really getting the desired id, because if its null it won't work. 首先,您可以像dd($company->id)一样调试id以确保您确实得到了所需的id,因为如果将其null将无效。

It sounds silly, but it happens.. 听起来很傻,但是它确实发生了。

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

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