17
app/Post.php
17
app/Post.php
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user