I am trying to print number of rows in Laravel from MySQL but i get this error: htmlspecialchars() expects parameter 1 to be string, object given (View: C:\wamp64\www\kont\resources\views\profile.blade.php)
I have two function inside my model. First function returns information about user from one table and another function counts number of friends for that user from another table. Please view my code below:
HomeController.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);
}
UserModel.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;
}
profile.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>
<td>Email</td>
<td><a href="mailto:info@support.com">{{ $d->email }}</a></td>
</tr>
<td>Website</td>
<td>
{{ $d->website }}
</td>
</tr>
@endforeach
@foreach($dt2 as $d2)
Number of friends: {{ $d }}
@endforeach