2018-01-01 04:00:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
2018-01-01 17:37:18 +00:00
|
|
|
use App\Jobs\TranslateSlug;
|
2018-01-01 04:00:45 +00:00
|
|
|
use App\Models\Topic;
|
|
|
|
|
|
|
|
// creating, created, updating, updated, saving,
|
|
|
|
// saved, deleting, deleted, restoring, restored
|
|
|
|
|
|
|
|
class TopicObserver
|
|
|
|
{
|
|
|
|
public function creating(Topic $topic)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2018-01-01 08:32:20 +00:00
|
|
|
public function saving(Topic $topic)
|
|
|
|
{
|
2018-01-01 12:18:33 +00:00
|
|
|
$topic->body = clean($topic->body, 'user_topic_body');
|
2018-01-01 08:32:20 +00:00
|
|
|
$topic->excerpt = make_excerpt($topic->body);
|
2018-01-01 17:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function saved(Topic $topic)
|
|
|
|
{
|
2018-01-01 13:22:16 +00:00
|
|
|
// 如 slug 字段无内容,即使用翻译器对 title 进行翻译
|
|
|
|
if (!$topic->slug) {
|
2018-01-01 17:37:18 +00:00
|
|
|
dispatch(new TranslateSlug($topic));
|
2018-01-01 13:22:16 +00:00
|
|
|
}
|
2018-01-01 08:32:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 04:00:45 +00:00
|
|
|
public function updating(Topic $topic)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
2018-01-31 15:00:57 +00:00
|
|
|
|
|
|
|
public function deleted(Topic $topic)
|
|
|
|
{
|
|
|
|
\DB::table('replies')->where('topic_id', $topic->id)->delete();
|
|
|
|
}
|
2018-01-01 04:00:45 +00:00
|
|
|
}
|