laravel - 下拉过滤器在 Laravel 5.8 中不起作用
问题描述
我尝试使用以下代码进行输入下拉过滤器:
<div class="col-md-2">
<div class="text-justify" >
<select class="itemName form-control form-filter" style="width:90px;" name="itemName" id="itemName">
@foreach($data as $category){
<option value="{{$category->Umur}}">{{$category->Umur}}</option>
@endforeach
</select>
</div>
</div>
但是,我的代码没有按我的预期运行(如下图所示) - 代码只调用数据库中的第一行。我应该用代码编辑什么?
解决方案
我自己也有这个问题,这就是我使用的:
<div class="form-group">
<div class="btn-group">
<input list="brow" class="form-control"name="instagram_account_id" id="instagram_account_id" placeholder="Search..">
<datalist id="brow">
@if($users->count() > 0)
@foreach($users as $user)
<option value="{{$user->id}}">{{ $user->username }}</option>
@endforeach
@else
No User(s) Found
@endif
</datalist>
</div>
</div>
至于我的控制器:
public function index()
{
$comments = Comment::paginate(10);
$users = InstagramAccount::all();
return view('instagramComments', [
'comments' => $comments,
'users' => $users,
]);
}
并且(如果你要使用它的形式)我在我的控制器中插入:
public function insert(Request $req)
{
$instagram_comment = $req->input('instagram_comment');
$instagram_account_id = $req->input('instagram_account_id');
$data = array('comment'=>$instagram_comment, 'account_id'=>$instagram_account_id);
DB::table('comments')->insert($data);
return redirect('/comments');
}
(如果使用上面的插入,请在您的网络路由中使用它):
Route::post('/locationsInsert', 'InstagramLocationsController@insert')->middleware('auth');
希望这对您有所帮助!
推荐阅读
- sitefinity - Sitefinity 没有缓存
- javascript - 如果我正在创建通用的“认识我们的团队”页面,如何知道点击的联系人按钮属于哪个团队成员?
- server - 允许 Active Directory 用户通过“用户和计算机”访问特定计算机
- image - 将颜色图应用于没有计数效果的二维数组
- windows - 如何从 OnPropertyValueChanged() 中为 PROPERTYKEY 获取有意义的值
- java - 所有 Keycloak 协议映射器配置选项都记录在哪里?
- c++ - C ++从具有自定义不可重复对象的临时参数的函数返回const引用
- javascript - ES5 类中的 JavaScript 原型继承范围
- macos - 如何检测和处理从 NSPathControl 到垃圾站图标的拖动?
- wpf - 在 Windows 10 上禁用绝对音量