【发布时间】:2020-06-06 21:54:01
【问题描述】:
我有一个使用 Laravel 生成一些代码的简单应用程序,现在我正在尝试使用 url 将唯一 id 传递给我的控制器。
这是应该接收 ID 的方法:
public function code($code_id)
{
$settings = Setting::find($code_id);
return view('pages.settings.code', compact('settings'));
}
这是我传递 ID 的视图文件:
<a href="{{ route('settings.code', $settings->code_id) }}">
{{ __('Generate Code') }}
</a>
当我检查我得到的 URL 时:
http://127.0.0.1:8001/settings/code?K1zMXRZG4
这是我的路线:
Route::get('settings/code', [
'as' => 'settings.code',
'uses' => 'SettingController@code'
]);
Route::resource('settings', "SettingController");
但我收到以下错误:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
Too few arguments to function App\Http\Controllers\SettingController::code(), 0 passed and exactly 1 expected
我的代码有什么问题?
【问题讨论】:
-
告诉我们你的
settings.code路线 -
好的,我会建议 KFoobar 在回答中告诉你的内容
标签: php laravel laravel-routing