lundi 28 mai 2018

Override primary key with foreign key in hasMany relation using laravel

Here are my tables

Posts

id | name | created_At

Comments

id | comment | post_id | created_at

Post Model

function comments(){
      return $this->hasMany('App\Models\Comment','id','post_id');
 }

PostsController

function index()
{
    Post::with('comments')::get();
}

Now how can i get list of all posts along with comments?

I am trying to match post_id in the child table.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire