phplaravelformshtml.dropdownlistfor

how do i add a link so that when i select an element in my dropdown menu i get redirected to thee page


Im trying to be able to be redirected to the page that the post is on when i select a post from a dropdown list of all my posts.

at the moment i have managed to populate the list with all of the post titles and i have added a link in the form of a to each element in the list but when i click on one of the elements nothing happens.

here is the code i use to populate the list:

<div class="col-md-10">
    <select class="form-control" id="post" name="post" required focus>
        @foreach($post as $posts)
            @if($posts->user_id == Auth::user()->id)
                <option value="/posts/{{$posts->id}}" selected>
                    <a href="/posts/{{$posts->id}}">
                        {{$posts->title}}
                    </a>
                </option>
             @endif       
         @endforeach
     </select> 
</div>

the page that i need to be redirected is in the following format:

/posts/id

where the id is the post id

How do i make this work?


Solution

  • You have to use like this

    <a class="dropdown-item" href="{{url('')}}/posts/{{$posts->id}}">{{$posts->title}}</a>