使用变量路由 Laravel

莫娜·穆尔

你好,这是我的控制器:

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]);
}

我希望用户可以选择一个“stellentyp”,然后应该显示带有“stellentyp”的视图。

但是我的路线有问题,他们不知道变量“stellentyp”。如何将控制器与路由连接?

我试过这个

Route::post('user/{$stellentyp}', 'StartController@getValues')->name('user.{$stellentyp}');

但它不起作用:(。错误是:

缺少 [Route: user] [URI: user/{$stellentyp}] 的必需参数。(查看:C:\xampp\htdocs\j4ylara\resources\views\user\start.blade.php)

莫娜·穆尔

我明白了:D

<form action="{{ action('StartController@getValues') }}" method="post" id="postData">
{{ csrf_field() }}
<select name="stellentyp">
    <option value="praktika">Praktika</option>
    <option value="fwd">Freiwilligendienste</option>
    <option value="jobs">Ferien- und/oder Nebenjobs</option>
</select>
<button type="submit">Jetzt finden</button>

这是我的blade.php

我的控制器是一样的,我的路线看起来像这样

Route::resource('user/start', 'StartController');
Route::post('user/angebote', 'StartController@getValues');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章