vendredi 31 août 2018

Laravel: Multiple Polymorphic relationships in a Eloquent Model

I have a Table Named Comment with following structure

Schema::create('model_notes', function (Blueprint $table) {
$table->increments('id');
$table->morphs('commentable');
$table->morphs('creatable');
$table->text('note');
$table->timestamps();
});

where I have two polymorphic relationships

commentable for any Article/Post or a Video

creatable for the comment Creator of the comment User/Admin

How to add comment against a Post created by a user?

I tried creating using following code

public function addComment($creatable, $comment)
{
        $this->comments()->create(['comment' => $comment, 'creatable' => $creatable]);
}

It did work

Thanks in advance!!!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire