ホーム画面にある検索フォームでitemsテーブルにある'name'(アイテム名)、'manufacturer'(メーカー名)の文字であいまい検索できるように処理を書いているのですが、文字を入力して検索ボタンを押しても
http://localhost:8000/bicycleapp/bicycleapp/home/searchResults?keyword=A
となり、404の画面が出てきます。
どう書いたらいいのでしょうか
itemController.php
PHP
1public function getItem(Request $request){ 2 $keyword = $request->input('keyword'); 3 $query = Item::query(); 4 if(!empty($keyword)){ 5 $query->where('name','like','%'.$keyword.'%')->orWhere('manufacturer','like','%'.$keyword.'%')->get(); 6 } 7 return view('home'); 8 } 9 public function searchResulte(Request $request){ 10 return view('searchResults',['items' => $items]); 11 } 12 13
ルーティングはこんな感じです
PHP
1Route::get('bicycleapp/home',('ItemController@getItem')); 2Route::get('bicycleapp/home/searchResults',('ItemController@searchResulte'));
ホーム画面にある検索フォーム
PHP
1<form class="form-inline" action="bicycleapp/home/searchResults" method="GET"> 2 <input type="text" name="keyword" value="" class="from-contorol float-right mr-2" value placeholder="検索"> 3 <input type="submit" value="検索" class="btn btn-info"> 4</form>
検索結果表示画面
PHP
1 @if($items != null) 2 @foreach($items as $item) 3<div class="card" style="width: 18rem;"> 4 <div class="card-body"> 5 6 <h3 class="card-title">{{$item->name}}</h3> 7 <h5>{{$item->manufacturer}}</h5> 8 <div class="weight">{{$item->weight}}g</div> 9 <a href="/bicycleapp/home/details/{{$item->id}}" class="btn btn-light">詳細</a> 10 </div> 11</div> 12 @endforeach 13 @endif 14 <a href="/bicycleapp/home">ホームへ</a>
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。