♻️ Factorise la suppression de tags

Pour #8
This commit is contained in:
2020-03-05 17:42:20 +01:00
parent d2d666da3b
commit d83d92ec42
2 changed files with 17 additions and 8 deletions

View File

@@ -14,16 +14,16 @@ class Post extends Model
protected $fillable = [
'content', 'image', 'date_post', 'user_id'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
];
/**
* The attributes that should be cast to native types.
*
@@ -32,4 +32,15 @@ class Post extends Model
protected $casts = [
'date_post' => 'datetime',
];
/**
* Delete this posts tags
*/
public function deleteTags()
{
$tags_to_delete = PostsTag::where('post_id', $this->id)->get();
foreach ($tags_to_delete as $tag_to_delete) {
$tag_to_delete->delete();
}
}
}