lundi 5 mars 2018

What is a user and a post's relationship to a post like?

This is what I have for my post likes relationship. I don't know if they are correct but a user can like many posts.

Post Like Table: User ID | Post ID

Post Like Model

public function post()
{
    return $this->belongsToMany(Post::Class);
}

public function user()
{
    return $this->belongsToMany(User::Class);
}

Post Model

public function user()
{
    return $this->belongsTo(User::Class);
}

public function post_likes()
{
    return $this->hasMany(PostLike::Class);
}

User Model

public function posts()
{
    return $this->hasMany(Post::Class);
}

public function post_likes()
{
    return $this->belongsToMany(PostLike::Class);
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2H8gD6N
via IFTTT

Aucun commentaire:

Enregistrer un commentaire