首页 > 解决方案 > 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)

标签: phplaravelroutes

解决方案


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.


推荐阅读