mysql - How to count all comments of a post of an user in laravel elloquent model? -


my 1 many relation declaration code in user model..

public function post() {    $this->hasmany('app\post', 'userid','id');// id--from user } 

my 1 many relation declaration code in post model..

  public function comment() {    $this->hasmany('app\comment', 'postid','pid');// id--from post } 

now want retrieve comment of user how?

try in user model

public function comments() {     return $this->hasmanythrough(                'app\comment', 'app\post',                 'userid', 'postid', 'id'     ); } 

https://laravel.com/docs/5.4/eloquent-relationships#has-many-through


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -