Laravel:htmlentities()期望参数1为字符串,给定数组

时间:2016-11-10 12:54:41

标签: php laravel

我正在开发一个Laravel项目,我需要编写一个自定义函数,但是当我调用这个函数时,Laravel说:

  

Laravel:htmlentities()期望参数1为字符串,给定数组

这是我的功能:

public static function get_checkup_time(){
    $user_logged_in = Auth::user()->foreignkey_id; 
    $result = DB::table('doctors')
               ->select('checkuptime')
               ->where(['id'=>$user_logged_in])
               ->get();
    return $result;
}

这是我试图调用此函数的view

@if(Auth::user()->userrolebit ==2)
    {{
        DateTimeFormat::get_checkup_time()
    }}
 @endif

我不知道我在这里做错了什么。

3 个答案:

答案 0 :(得分:1)

where()期望string为第一个参数,因此请更改:

->where(['id'=>$user_logged_in])

到此:

->where('id', $user_logged_in)

答案 1 :(得分:0)

如果您尝试仅返回检查时间,则应在方法中执行此操作

$sql = "SELECT noticeID, notice, noticeDesc, noticeIMG, noticeDate,
expiryDate FROM tbl_notices GROUP BY noticeID ,expired ORDER BY expiryDate ASC";
$result = mysqli_query($conn,$sql);

        if ($result->num_rows > 0)
        {
            // output data of each row
            while($row = $result->fetch_assoc())
            {
                $id = $row['noticeID'];
                $title = htmlspecialchars($row['notice']);
                $urltitle = strtolower($title);
                $urltitle = str_replace(" ","-",$urltitle);
                $date = $row['noticeDate'];
                $datetime1 = new DateTime("2010-06-20");
                $expiryDate = $row['expiryDate'];
                $link = "announcements.php";
                $body = strip_tags($row['noticeDesc']);
                $filename = $row['noticeIMG'];
                if($filename != "")
                {
                    $imgLink = "images/".$filename;
                }
                else
                {
                    $imgLink = "images/announcement-default.jpg";
                }?>

                <div class="news-container-sm">
                    <img class="pin" src="images/thumbtack_pushpin_2_thumb.png" alt="News Pin" title="News Pin">
                    <div class="news-img"><img class="fluid" src="<?php echo $imgLink?>" alt="<?php echo $title?>" title="<?php echo $title?>" /></div>
                        <div class="fluid news-headline"><?php echo $title?>
                            <span class="fluid news-date"><?php echo "expires in ".humanTiming( strtotime($expiryDate) );?></span>
                        </div>
                    <div class="fluid news-desc"><?php echo $body;?></div>
                </div><?php
            }           
        }
        else
        {
            echo "No Announcements!";
        }
        $conn->close();?>

答案 2 :(得分:-1)

修改

通过downvote,我发现我的作品也不会正常工作,因为->get()来电应该被->first()替换,就像在@Paul的回答中一样。请参阅下面的评论。

从方法返回的$result不是字符串。

因此{{ DateTimeFormat::get_checkup_time() }}是返回错误的那个。

返回类似$result->checkuptime的内容应该这样做。