1 public function comments()
2 {
3 return $this->hasMany(Comment::class);
4 }
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6
7class Post extends Model
8{
9 /**
10 * Get the comments for the blog post.
11 */
12 public function comments()
13 {
14 return $this->hasMany('App\Models\Comment');
15 }
16}
1class Post extends Model
2{
3 public function comments()
4 {
5 return $this->hasMany(Comment::class, 'foreign_key', 'local_key');
6 // local id is the main id Of post table such as : id
7 // foreign id is the post table which is inside comment table such as: post_id
8 //return $this->hasMany(Comment::class, 'post_id', 'id');
9 //return $this->hasMany(Comment::class, 'post_id');
10
11
12 }
13}