Bonjour,
Voila je rencontre un petit problème avec mon code.
Je voudrais count tous les like de tous les commentaires de l'utilisateur
count(array_keys($comment, "like")),
ERREUR: array_keys() expects parameter 1 to be array, object given
En réfléchissant c'est normal.
Alors soit tu rajoute un champ like_count a ta table users que tu augment/diminue a chaque like/dislike sur un commentaire du membre ou alors tu fait un foreach des comentaires et tu compte les likes.
$comments = Comment::where('comment_id', 0)->where('author', $user->id)->get();
$likes = 0;
foreach ($comments as $comment){
$likes += $comment->like;
}
je fait comment alors ? la requette : $comment = Comment::where('comment_id', 0)->where('author', $user->id)->get();
j'utilise laravel donc : object(Illuminate\Database\Eloquent\Collection)[306]
protected 'items' =>
array (size=3)
0 =>
object(App\Comment)[307]
protected 'fillable' =>
array (size=7)
...
protected 'connection' => null
protected 'table' => null
protected 'primaryKey' => string 'id' (length=2)
protected 'keyType' => string 'int' (length=3)
protected 'perPage' => int 15
public 'incrementing' => boolean true
public 'timestamps' => boolean true
protected 'attributes' =>
array (size=11)
...
protected 'original' =>
array (size=11)
...
protected 'relations' =>
array (size=0)
...
protected 'hidden' =>
array (size=0)
...
protected 'visible' =>
array (size=0)
...
protected 'appends' =>
array (size=0)
...
protected 'guarded' =>
array (size=1)
...
protected 'dates' =>
array (size=0)
.......
j'ai fait $arrays[] = $comment->toArray(); pour le mettre en arrays et donc apres pour eco les key : dd(array_keys($arrays, "like")) mais il me retourne un tableau vide