Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel has many with ids

class Post extends Model
{
  public function comments()
  {
  	return $this->hasMany(Comment::class, 'foreign_key', 'local_key');
 // local id is the main id Of post table such as : id
 // foreign id is the post table which is inside comment table such as: post_id
    //return $this->hasMany(Comment::class, 'post_id', 'id');  
    //return $this->hasMany(Comment::class, 'post_id'); 


  }
}
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel #ids
ADD COMMENT
Topic
Name
3+8 =