我正在尝试从 MySQL 打印 Laravel 中的行数,但出现此错误: htmlspecialchars() expects parameter 1 to be string, object given (View: C:\wamp64\www\kont\resources\views\profile.blade. PHP)
我的模型中有两个函数。第一个函数从一个表返回有关用户的信息,另一个函数从另一个表计算该用户的朋友数。请在下面查看我的代码:
家庭控制器.php
public function profile(Request $request,$id){
$model = new UserModel();
$podaciIzBaze = $model->userdata($id);
$data = array();
$data['dt'] = $podaciIzBaze;
$model2 = new UserModel();
$podaciIzBaze2 = $model2->countfriends($id);
$data['dt2'] = $podaciIzBaze2;
return view('profile',$data);
}
用户模型.php
class UserModel extends Model
{
//
public function userdata($id){
$query = DB::select("SELECT first_name,last_name,email,website,birth_date FROM users where id = $id");
return $query;
}
public function countfriends($id){
$query=DB::SELECT("SELECT count(user_id) from user_friend where user_id = $id");
return $query;
}
配置文件.blade.php
@foreach($dt as $d)
<tr>
<td>Ime:</td>
<td>{{ $d->first_name }}</td>
</tr>
<tr>
<td>Prezime</td>
<td>{{ $d->last_name }}</td>
</tr>
<tr>
<td>Datum Rodjenja</td>
<td>{{ $d->birth_date }}</td>
</tr>
<tr>
<tr>
<td>Pol</td>
<td>Musko</td>
</tr>
<tr>
FFIVE
喵喔喔
喵喵时光机