当我使用all()数据显示但当我选择查找时或当我在laravel中使用dd函数时数据不显示时,有些让我在laravel中感到困惑
//$regency = Regency::find(1101);
//$regency = Regency::where('number','=',$prov_id);
$regency = DB::table('regencies')->where('province_id', $prov_id);
dd($regency);
我尝试使用雄辩的查询生成器,但结果仍然相同。 those is result in dd if i using query builder, but why when i use select all data is showing
答案 0 :(得分:1)
您要显示的是table_2 = {'Name': {'20': 'Paul Merrill', '21': 'Brynne S. Barr', },
'Phone': {'20': '1-313-739-3854', '21': '939-4818', },
'Address': {'20': '916-8087 Vehicula Rd.', '21': '878-2231 Suspendisse Rd.', },
'City': {'20': 'Le Mans', '21': 'Wilhelmshaven',}}
# you can get the list of keys to get the values
values_list = []
key_list = [v.keys() for v in table_2.values()]
keylist = []
for key in key_list:
keylist = list(key)
for i in keylist:
values_list.append([i, table_2.get('Name').get(i), table_2.get('Phone').get(i),
table_2.get('Address').get(i), table_2.get('City').get(i)])
print(values_list)
,您需要使用Query Builder
执行它才能获得集合。
答案 1 :(得分:0)
您必须从查询生成器中获取数据,以便以对象集合的形式接收结果
// $regency = Regency::findOrFail(1101);
// $regency = Regency::where('number', $prov_id)->get();
$regency = DB::table('regencies')->where('province_id', $prov_id)->get();
dd($regency);
编写查询生成器只会产生SQL查询,但实际上并不会执行/运行
希望这会有所帮助