Php Laravel将管线参数修改为名称列而不是id

Php Laravel将管线参数修改为名称列而不是id,php,laravel,variables,laravel-5,http-status-code-404,Php,Laravel,Variables,Laravel 5,Http Status Code 404,在我的web.php文件中,我指定以下路径: Route::get('/{project}', 'ProjectsController@index'); 在我的ProjectsController中,我将公共函数索引定义如下: use App\Project; // ... Here is the class declaration etc. public function index(Project $project) { dd($project->name); } 目前,我的p

在我的
web.php
文件中,我指定以下路径:

Route::get('/{project}', 'ProjectsController@index');
在我的ProjectsController中,我将公共函数
索引定义如下:

use App\Project;
// ... Here is the class declaration etc.
public function index(Project $project) {
  dd($project->name);
}
目前,我的projects表中有一个条目,我可以调用它,而不会对我的雄辩模型产生任何问题。这是我的作品:

Name: sampleproject
Description: This is a test.
ID: 1
// And the timestamps...
调用
/sampleproject
时,返回404错误页。
[……]

更新:调用项目id的
/1
时,一切正常。如何修改代码,以便通过项目名称而不是id调用控制器?

在您的模型中:

公共函数getRouteKeyName()
{
返回'yourcolumn';
}
在您的型号中:

公共函数getRouteKeyName()
{
返回'yourcolumn';

}
你可以查看文档:@VincentDecaux我已经看完了那一页,但我似乎忽略了那一部分。谢谢你可以看看医生:@VincentDecaux我已经看完了那一页,但我似乎忽略了那一部分。谢谢