[英]Laravel htmlentities() expects parameter 1 to be string, array given
[英]Laravel : htmlentities() expects parameter 1 to be string, array given
我正在開發一個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
我不知道我在這里做錯了什么。
where()
期望string作為第一個參數,所以改變這個:
->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;
}
編輯:
在downvote之后,我已經看到我的工作也不行,因為->get()
調用應該替換為->first()
如@Paul的答案。 請參閱下面的評論。
從方法返回的$result
不是字符串。
因此{{ DateTimeFormat::get_checkup_time() }}
是返回錯誤的那個。
返回類似$result->checkuptime
東西應該這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.