我正在尝试生成唯一ID,然后在url参数中重定向到id不同的路由。但我得到的错误是:
“路线[序列]未定义。”
这是我定义的路线:
Route::get('/sequences_create','SequencesController@create');
Route::get('/sequences/{id}', 'SequencesController@show');
这是序列控制器上的create函数:
public function create()
{
$uniq = 'seq'. uniqid();
$seq = new Sequences;
$seq->id = $uniq;
$seq->user_id = auth()->user()->id;
$seq->name = 'New Sequence'; //temp name
$seq->save();
return redirect()->route('sequences', ['id' => $uniq]);
}
答案 0 :(得分:2)
您需要为自己的路线命名。
Route::get('/sequences_create','SequencesController@create')->name('sequences.create');
Route::get('/sequences/{id}', 'SequencesController@show')->name('sequences.show');
然后将您的重定向更改为:
return redirect()->route('sequences.show', ['id' => $uniq]);
答案 1 :(得分:2)
您尚未通过name()
方法为路线设置名称。
试一试:
Route::get('/sequences_create','SequencesController@create')->name('sequances.create');
Route::get('/sequences/{id}', 'SequencesController@show')->name('sequances.show');
然后:
public function create()
{
//...
return redirect()->route('sequences.show', ['id' => $uniq]);
}