mercredi 13 mars 2019

hasMany, belongsTo, belongsToMany parameters with custom names?

I have these db tables:

author (atr_id pk)                              // model : Author
category (ctg_id pk)                            // model : Category
post (pst_id pk, pst_atr_id fk)                 // model : Post
post_categories (pct_pst_id fk, pct_ctg_id fk)  // pivot : PostCategories 

how to define the hasMany, belongsTo, belongsToMany parameters with custom names?

Model : Author

public function getPosts()
{
    return $this->hasMany('App\Post', ?, ?);
}

Model : Post

public function getAuthor()
{
    return $this->belongsTo('App\Author', ?, ?);
}

public function getCategories()
{
    return $this->belongsToMany('App\Category', ?, ?, ?);
}

Model : Category

public function getPosts()
{
    return $this->belongsToMany('App\Post', ?, ?, ?);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire