REFACTORING: move content update and create logic into separate interactions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user