[英]Laravel No query results for model [App\Topic] create
我正在尝试获取用户能够创建主题的视图。 我在我的项目中多次这样做但从未遇到过这个错误,因为所有其他的工作都很好。
我收到错误No query results for model [App\\Topic] create
。 这是代码。
这是应该将用户带到视图的链接。
<div class="col s12">
<div class="card">
<div class="card-content clearfix">
<a href="{{ route('createtopic', ['theme_id' => $theme->id]) }}" class="waves-effect waves-light btn blue-grey darken-4">New topic <i class="material-icons right">edit</i></a>
</div>
</div>
</div>
这些是此问题中使用的路由。
Route::get('/theme/{theme_id}/topics/create', 'TopicsController@create')->name('createtopic');
Route::post('/theme/{theme_id}/topics/create', 'TopicsController@store')->name('savetopic');
Controller方法创建。
dd('Hij is er ' . $id);
并且store方法为空,链接不显示DumpDie方法,而是显示错误。 因此,没有必要发布我想要显示的视图,因为这不是问题所在。 提前致谢!
您需要了解路由和控制器方法的工作原理
Route::get('/theme/{theme_id}/topics/create', 'TopicsController@create')->name('createtopic');
当您点击上述路线时,我的意思是你的浏览器中有例如yourdomain/theme/1/topics/create
,然后它将取代1
替换theme_id
,它将转到你的TopicsController
的create
方法,它将接受一个论点。
你的create方法应该是这样的
public function create($id)
{
dd($id);
}
在这里你将获得1作为结果,因为你已经在你的网址而不是theme_id中传递了这个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.