I'm building a blogging app with laravel with the functionality to like a post (only once by a user) with a thumbs-up icon. I have set up a model each for User, Post and Like with their respective tables. The likes table consist of user_id,post_id and the timestamps columns. I have also defined relationships between User and Post models like so: Inside User model:
Public function post(){
return $this->hasMany (App\Post)
}
Public function like(){
return $this->hasMany (App\Like)
}
and inside Post model;
Public function user(){
return $this->belongsTo (App\User)
}
My challenge however is in writing a relationship between Post and Like models. What relationships will exist between both models?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire