2016-10-06 12 views
0

フォーム(dropdwon)から値を渡して、この値をURLに追加する必要があります。Laravel 5.2 paramsをURLに追加

私のルートは以下のとおりです。

{!!Form::open(array('action' => '[email protected]', 'method' => 'POST'))!!} 
     {!! Form::select('city', array('heilbronn' => 'Heilbronn', 'stuttgart' => 'Stuttgart')) !!} 
     {!!Form::submit('Senden')!!} 
{!!Form::close()!!} 

そしてこのコントローラー:

public function menue(Request $request, $city = null) { 
    $searchinput = $request->input('city'); 

    $restaurants = User::with(['articles' => function ($q){ 
     $q->nowpublished(); 
    }]); 

    if(!is_null($city) && !is_null(User::where('city', $city)->first())) { 
     $restaurants->where('city', '=', $city); 
    } 

    $restaurants = $restaurants->get();  

    return view('pages.menues')->withRestaurants($restaurants) 
          //->withArticles($articles) 
          ->withCity($city) 
          ->withSearchinput($searchinput);         
} 

は私が値($のsearchinput)を追加する必要があるから

Route::get('menues/{city?}', '[email protected]'); 
Route::post('/', '[email protected]'); 

は、私は簡単なフォームを持っています特定の都市のエントリのみを表示する前のページ。

答えて

1

あなたが得るためにあなたのフォームmethod属性を変更する必要があり、その後、あなたのコントローラにあなたが続くことが可能です。

public function menue(Request $request) { 
    $city = $request->city; 

    // bla-bla-bla 

    if (! is_null($city) && && ! is_null(User::where('city', $city)->first()) { 
    // bla-bla 
    } 

    // return 
} 
+0

とルート 'にあなたのルートを変更する::(「menues」、「をPagesController @ menue」を取得); ' – astratyandmitry

+0

ありがとうastratyandmitry。働いた! – Mamulasa

+0

あなたは大歓迎です:) – astratyandmitry

関連する問題