$dept_name = DB::table('departments')->select('dept_name')->where('id', '=', $request->alloted_dept)->get();
strong text**dd ($dept_name);
我想只打印部门名称,但在浏览器中显示 输出:
array:1 [▼
0 => {#269 ▼
+"dept_name": "IPS department"
}
]
在echo $ dept_name上输出
ErrorException in abcController.php line 34: Array to string conversion
我想只输出“IPS部门”。
答案 0 :(得分:0)
你必须循环你的结果
$dept_name = DB::table('departments')->select('dept_name')->where('id', '=', $request->alloted_dept)->get();
foreach($dept_name as $name) {
echo $name;
}
@foreach($dept_name as $name)
{{ $name }}
@endforeach
答案 1 :(得分:0)
我是这样做的:
$dept_name = DB::table('departments')->select('dept_name')->where('id', '=', $request->alloted_dept)->get();
$dept = "";
foreach($dept_name as $name) {
$dept = $name->dept_name;
}
echo $dept;
输出:
IPS department
感谢您回答Saravanan Sampathkumar