Php larvel:htmlentities()期望参数1是字符串,数组给定

Php larvel:htmlentities()期望参数1是字符串,数组给定,php,laravel,Php,Laravel,我正在从事一个Laravel项目,其中我需要编写一个自定义函数,但当我调用此函数时,Laravel说: larvel:htmlentities()期望参数1是字符串,数组给定 以下是我的功能: public static function get_checkup_time(){ $user_logged_in = Auth::user()->foreignkey_id; $result = DB::table('doctors') ->

我正在从事一个Laravel项目,其中我需要编写一个自定义函数,但当我调用此函数时,Laravel说:

larvel: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;
}
这是我的
视图
,我试图在其中调用这个函数

@if(Auth::user()->userrolebit ==2)
    {{
        DateTimeFormat::get_checkup_time()
    }}
 @endif
我不知道我在这里做错了什么。

where()
需要字符串作为第一个参数,所以请更改此选项:

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

->where('id', $user_logged_in)
where()
需要字符串作为第一个参数,因此请更改此选项:

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

->where('id', $user_logged_in)

如果您试图返回检查时间,您应该在您的方法中执行此操作

public static function get_checkup_time()
{
    $user_logged_in = Auth::user()->foreignkey_id; 

    $result = DB::table('doctors')
               ->select('checkuptime')
               ->where('id', $user_logged_in)
               ->first();

    return $result->checkuptime;
}

如果您试图返回检查时间,您应该在您的方法中执行此操作

public static function get_checkup_time()
{
    $user_logged_in = Auth::user()->foreignkey_id; 

    $result = DB::table('doctors')
               ->select('checkuptime')
               ->where('id', $user_logged_in)
               ->first();

    return $result->checkuptime;
}
编辑:

在一次否决投票后,我发现我的方法不起作用,因为在@Paul的回答中,
->get()
调用应该被
->first()
替换。见下面我的评论


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

因此,
{{DateTimeFormat::get_checkup_time()}}
是返回错误的

返回类似于
$result->checkuptime
的内容就可以了。

编辑:

在一次否决投票后,我发现我的方法不起作用,因为在@Paul的回答中,
->get()
调用应该被
->first()
替换。见下面我的评论


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

因此,
{{DateTimeFormat::get_checkup_time()}}
是返回错误的


返回类似于
$result->checkuptime
的内容就可以了。

你能解释一下否决票吗?密码有问题吗?你能解释一下否决票吗?“密码有问题吗?”保罗的回答是正确的,我的密码不起作用。调用
->first()
而不是
->get()
是返回正确属性之前的关键。幸好他比我先发布了一个答案:)@保罗的答案是正确的,我的答案不起作用。调用
->first()
而不是
->get()
是返回正确属性之前的关键。幸好他比我先发布了一个答案:)你不能只是“打印”数组。嗯,你可以,但结果肯定毫无意义。我很确定你想从数组中提取
checkuptime
。你不能只是“打印”数组。嗯,你可以,但结果肯定毫无意义。我很确定您想从数组中提取
checkuptime