php - 类似“类 std 类的对象无法转换为字符串”之类的错误
问题描述
这是我的控制器
function index()
{
$name_list = DB::table('customers')
->groupBy('first_name')
->get();
$name_list2 = DB::table('customers')
->where('first_name', $name_list)->first();
return view('dynamic_field')->with('name_list2',$name_list2);
}
这是我的观点,我正在用 javascript 进行检索。
@foreach($name_list2 as $name)
'<option value="{{ $name->first_name}}">{{ $name->first_name }}</option>'+
@endforeach
解决方案
You don't need to foreach
$name_list2
as this is a single record being fetched from the database as per your query.
You can try this without using foreach
:
{{ $name->first_name}}
Hope it helps!
推荐阅读
- android - 我不断收到无法访问 Cloud Firestore 后端。后端未在 10 秒内响应(Firestore)
- facebook-graph-api - 如何在 Facebook 图形 API URL 中指定广告集 ID
- entity-framework-core - 联合无法转换为 SQL
- python - 如何通过硒打开新网站,然后打开新标签并关闭新标签并使用python中的第一个标签
- ios - 在 Ionic 3.9.2 IOS 版本中实现 RTCMultiConnection(流音频)的问题
- c# - 未调用 Main(string[] args) 方法
- angular - 如何在 [(ngModel )] 中使用条件
- vb.net - 如何修复表单“项目目录中的“Form1.vb”项目未退出。它可能已被移动、重命名或删除
- javascript - 在 html onclick 中推送到 ViewController
- javascript - Restful API 打字稿和承诺