i have some issue when i wanna count row from relation table
i have 2 tables users and threads i wanna count all threads by id_user.
this in User model
public function thread(){
return $this->hasMany('App\Thread');
}
protected $primaryKey = "id";
this in Thread Model
protected $primaryKey = "id";
public function user(){
return $this->belongsTo('App\User','id_users');
}
i try to count in my view like this
and this is my index method in controller
public function index()
{
$users = Auth::user();
$threads = Thread::orderBy('created_at','desc')
->get();
return view('/home',compact('threads','users'));
}
i just put descending for showing data in my controller.
anyone have solution for this issue ???
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire