REFACTORING: move content update and create logic into separate interactions

This commit is contained in:
Michal Kváček
2016-10-17 02:52:30 +02:00
parent 6ec692bd1c
commit eabbf48ee0
13 changed files with 271 additions and 141 deletions
+19
View File
@@ -2,6 +2,8 @@
namespace App\Models\Content;
use App\Events\CreateNewContent;
use App\Events\Event;
use App\Models\FileManager\File;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
@@ -108,8 +110,25 @@ class Content extends Model
return $this->belongsToMany(File::class, 'contents_has_files');
}
/**
* Category of content page
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function category()
{
return $this->belongsTo(Category::class);
}
public function save(array $options = [])
{
$saved = parent::save($options);
// fire event about creating new content page
if ($this->wasRecentlyCreated) {
Event::fire(new CreateNewContent($this));
}
return $saved;
}
}