I want to remove the relationship between two models in a one-to-one polymorphic relationship. In the example below, I want both comment and post to exist but just remove the relationship netween them. That is I want to set commentable_id and commentable_type to null.
posts
    id - integer
    title - string
    body - text
videos
    id - integer
    title - string
    url - string
comments
    id - integer
    body - text
    commentable_id - integer
    commentable_type - string
relationship:
class Comment extends Model
{
    public function commentable()
    {
        return $this->morphTo();
    }
}
class Post extends Model
{
    public function comments()
    {
        return $this->morphOne('App\Comment', 'commentable');
    }
}
class Video extends Model
{
    public function comments()
    {
        return $this->morphOne('App\Comment', 'commentable');
    }
}
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire