Reputation: 115
I am implementing a drop down menu list to display a list of hotels from my system. I currently have the following code which when i click submit, nothing is happening (no data displayed).
Does anyone know how i can potentially display data once i press submit. I do believe i need code in my controller.
SEARCH.BLADE.PHP
<form action="/search" method="POST" role="search">
<div class="form-group">
<select name="country" id="country" class="form-control input-lg dynamic" data-dependent="state">
@foreach($posts as $post)
<option value="{{$post->distance}}">{{$post->distance}} </option>
@endforeach
<br/>
<div class="form-group">
<select name="state" id="state" class="form-control input-lg dynamic" data-dependent="city">
</select>
</div>
<br />
<div class="form-group">
<select name="city" id="city" class="form-control input-lg">
@foreach($posts as $post)
<option value="{{$post->title}}">{{$post->title}} </option>
@endforeach
</div>
</select>
</div>
</div>
{{Form::Submit('submit', ['class' => 'btn btn-primary'])}}
</body>
SearchController.php
class SearchController extends Controller {
public function index()
{
$posts = Post::all();
return view('Pages.search')->with('posts', $posts);
}
I do not have much is the search controller but i do believe i need some code in there to display the data.
Upvotes: 2
Views: 1743
Reputation: 375
use App\Post;
public function index()
{
$posts = Post::latest()->get();
return view('search',compact('posts'));
}
@foreach($posts as $post)
<option value="{{$post->id}}">{{$post->title}} </option>
@endforeach
Upvotes: 1
Reputation: 6005
Use this
<form action="/search" method="POST" role="search">
<div class="form-group">
<select name="country" id="country" class="form-control input-lg dynamic" data-dependent="state">
@foreach($posts as $post)
<option value="{{$post->id}}">{{$post->title}} </option>
@endforeach
</select>
</div>
<div class="form-group">
<select name="city" id="city" class="form-control input-lg">
@foreach($posts as $post)
<option value="{{$post->id}}">{{$post->title}} </option>
@endforeach
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-adminsqure pull-right submitbutton"> Submit</button>
</div>
Also change in your controller
class SearchController extends Controller {
public function index()
{
$posts = Post::get();
return view('Pages.search', compact('posts'));
}
Upvotes: 1