2

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.

11
  • close your <select> tag with </select>, and debug $posts to insure in has data from database Commented Feb 20, 2020 at 12:12
  • You need to pass data to Controller Function and write a query for search ,close you select tag and form Commented Feb 20, 2020 at 12:13
  • i removed the select tag in this instance as it was too much code. Are you able to write code of what it should be in the controller ? Commented Feb 20, 2020 at 12:16
  • you need to close your </select> tags. also you can clean up your controller code with using compact return view('Pages.search', compact('posts')); Commented Feb 20, 2020 at 12:18
  • <button type="submit" class="btn btn-adminsqure pull-right submitbutton"> Submit</button> Commented Feb 20, 2020 at 12:26

2 Answers 2

1

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'));
  }
Sign up to request clarification or add additional context in comments.

2 Comments

not what i was looking for as the data appears in the drop down menus, however when i click submit, the data is not showing on my screen. How do i link the submit button to my code ?
but how would i exactly get the data to display when i click submit. ATM its not doing anything
1
 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.