php - routes laravel with a variable
问题描述
Hello this is my controller:
public function getValues(Request $request){
$typ=$request->get('typ');
$stellentyp=$request->get('stellentyp');
$bereich=$request->get('bereich');
$view = 'user.'.$stellentyp;
return view($view,['typ' => $typ, 'stellentyp', $stellentyp, 'bereich', $bereich]);
}
I want that the user can select a "stellentyp" and then the view with that "stellentyp" should be shown.
But I have a problem with my routes, they do not know the variable "stellentyp". How can I connect my controller with my routes?
I tried this
Route::post('user/{$stellentyp}', 'StartController@getValues')->name('user.{$stellentyp}');
but it does not work :(. The error is:
Missing required parameters for [Route: user] [URI: user/{$stellentyp}]. (View: C:\xampp\htdocs\j4ylara\resources\views\user\start.blade.php)
解决方案
Route::post('user/{stellentyp}', 'StartController@getValues')->name('user.values');
In order to add a variable inside the route path you don't have to use the dollar signal to declare it. Check above code. Also the name of the route does not have to be dynamically assigned.
推荐阅读
- c++ - 如何在 VS Code 中进行 C++ 开发的初始设置?
- ios - 即使我的 swift 代码显示 firebase 登录中发生错误,它也会执行 segue
- shell - 目录中的长列表值和计算值
- android - 如何从 Firebase 中删除包含图像的文件夹?
- transactions - 可靠的事件日志(不是真正的事件溯源)
- java - 使用流和 Callables 的 Java ThreadPoolExexecutor
- python - 2 GET 路由到 Flask-RESTful 中的相同资源
- android-studio - Android Spinner 将下拉文本方向设置为 RTL
- variables - 如何在计算机内存中存储和访问变量及其引用?
- android - Android Studio 关闭键盘并完成活动