2019-09-18 16:50:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Post extends Model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
'content', 'image', 'date_post', 'user_id'
|
|
|
|
];
|
2020-03-05 17:42:20 +01:00
|
|
|
|
2019-09-18 16:50:01 +02:00
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
2020-03-05 17:42:20 +01:00
|
|
|
|
2019-09-18 16:50:01 +02:00
|
|
|
];
|
2020-03-05 17:42:20 +01:00
|
|
|
|
2019-09-25 15:20:22 +02:00
|
|
|
/**
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'date_post' => 'datetime',
|
|
|
|
];
|
2020-03-05 17:42:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
}
|
2019-09-18 16:50:01 +02:00
|
|
|
}
|