gpt4 book ai didi

Laravel:使用下拉列表显示数据

转载 作者:行者123 更新时间:2023-12-04 10:33:11 26 4
gpt4 key购买 nike

我正在实现一个下拉菜单列表来显示我系统中的酒店列表。我目前有以下代码,当我点击提交时,什么也没有发生(没有显示数据)。

有谁知道我按下提交后如何潜在地显示数据。我相信我的 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);
}

我没有太多的搜索 Controller ,但我相信我需要一些代码来显示数据。

最佳答案

用这个

<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>

还要更改您的 Controller
class SearchController extends Controller { 

public function index()
{
$posts = Post::get();
return view('Pages.search', compact('posts'));
}

关于Laravel:使用下拉列表显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60319541/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com