2017-04-17 76 views
0

我正在重新編寫我的網站並轉移到Laravel,但由於某種原因,我無法弄清楚如何擁有將您重定向到配置文件頁面的搜索表單。Laravel 5表單提交到查看

<form class="navbar-form navbar-right search" role="search" action="/profile/" method="GET"> 
<div class="input-group"> 
<input type="text" class="form-control navbar-player-search" placeholder="Enter IGN here" autocomplete="off" required> 
     <div class="input-group-btn"> 
      <button type="submit" class="btn btn-default"> 
       <i class="glyphicon glyphicon-search"></i> 
      </button> 
     </div> 
    </div> 
</form> 

我有一個路徑已經建立,如果我去example.com/profile/Callahan

Route::get('/profile/{Profile}', '[email protected]'); 

其作品,但我需要的形式做同樣的事情。 是否可以使用默認的laravel 5.4.3來做到這一點,或者我需要像https://laravelcollective.com/docs/5.3/html這樣的東西嗎?

回答

0

我完全不明白其中輸入包含的信息,但我會考慮這個問題:

用戶將輸入寫,然後點擊搜索。 然後,在您的控制器中,您將在搜索並重定向到配置文件後獲取配置文件名稱。是這樣嗎?

如果是的話,你應該做這樣的事情:

路由

Route::get('/profile/{Profile}', '[email protected]'); 
Route::get('/search', '[email protected]'); 
Route::post('/search', '[email protected]'); 

控制器

public function searchForm() { 
    return view('search'); 
} 

public function search(Request $request) { 
    // get the input 
    $inputText = ...; 
    // logic to get the profile name 
    $profileName = ...; 
    return redirect('/profile/'.$profileName); 
} 

查看

<form class="navbar-form navbar-right search" role="search" action="/search" method="POST"> 
<div class="input-group"> 
<input type="text" class="form-control navbar-player-search" placeholder="Enter IGN here" autocomplete="off" required> 
     <div class="input-group-btn"> 
      <button type="submit" class="btn btn-default"> 
       <i class="glyphicon glyphicon-search"></i> 
      </button> 
     </div> 
    </div> 
</form> 

再一次,我不知道這是你真正想要的,但如果不是,讓我知道再次嘗試幫助你。

+0

public function searchForm(){ return view('search'); } 需要是刀片視圖嗎? – Callahan

+0

我有在頂部的導航欄中的HTML搜索條碼,在舊的網站上,我只是提交發布數據到頁面,然後檢查是否發送了數據並將它們重定向到那裏 – Callahan

+0

有沒有必要使用刀片。該文件可能只是.php,並會正常工作。對,所以這些代碼適合你? –