laravel-learn-bbs/app/Observers/TopicObserver.php
2018-01-02 01:37:18 +08:00

36 lines
731 B
PHP

<?php
namespace App\Observers;
use App\Jobs\TranslateSlug;
use App\Models\Topic;
// creating, created, updating, updated, saving,
// saved, deleting, deleted, restoring, restored
class TopicObserver
{
public function creating(Topic $topic)
{
//
}
public function saving(Topic $topic)
{
$topic->body = clean($topic->body, 'user_topic_body');
$topic->excerpt = make_excerpt($topic->body);
}
public function saved(Topic $topic)
{
// 如 slug 字段无内容,即使用翻译器对 title 进行翻译
if (!$topic->slug) {
dispatch(new TranslateSlug($topic));
}
}
public function updating(Topic $topic)
{
//
}
}