为了账号安全,请及时绑定邮箱和手机立即绑定

ErrorException htmlspecialchars()期望参数1为字符串,给定数组

ErrorException htmlspecialchars()期望参数1为字符串,给定数组

PHP
月关宝盒 2021-04-08 21:19:33
我想从数据库中获取数据“ report_to”。但是,当我尝试在视图页面中打印变量时出现错误。据说“ ErrorException htmlspecialchars()期望参数1为字符串,给定数组”。这是我的控制器。function editroledetails(Request $request)    {        $user = \Auth::user();        $userphone = 0;        $reportTo = DB::select(DB::raw("SELECT report_to FROM customer_type WHERE username='19331986' "));        $data = [            'editUsername' => $request->editUsername,            'editNik' => $request->editNik,            'editEmail' => $request->editEmail,            'editRegIdentities' => $request->editRegIdentities,            'editID' => $request->editID        ];        return view('editroledetails', compact('user', 'userphone', 'data', 'reportTo'));    }这是我的看法<div class="alert alert-info">            <h3>{{$reportTo}}</h3>        </div>我希望该视图将显示为“名称”的变量,但是我收到了错误htmlspecialchars()期望参数1为字符串,给定数组。
查看完整描述

3 回答

?
开满天机

TA贡献1786条经验 获得超13个赞

改变

$reportTo = DB::select(DB::raw("SELECT report_to FROM customer_type WHERE username='19331986' "));

$reportTo = DB::select(DB::raw("SELECT report_to FROM customer_type WHERE username='19331986' "))->get();

现在$reportTo是您可能需要使用@foreach或的数组@for。或者,如果你相信你会得到一个记录,你可以使用first()

$reportTo = DB::select(DB::raw("SELECT report_to FROM customer_type WHERE username='19331986' "))->first();



查看完整回答
反对 回复 2021-04-23
?
慕仙森

TA贡献1827条经验 获得超8个赞

您必须检查report_id是否为数组:


<div class="alert alert-info">

        @if(is_array())

            @foreach($reportTo as $rep_to)

             <h3>{{$rep_to}}</h3>

            @endforeach

        @else

           <h3>{{$reportTo}}</h3>

        @endif

    </div>


查看完整回答
反对 回复 2021-04-23
  • 3 回答
  • 0 关注
  • 182 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信