32 lines
724 B
PHP
32 lines
724 B
PHP
<?php
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Models\Topic;
|
|
use App\Tools\SlugTranslateHandler;
|
|
|
|
// 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);
|
|
// 如 slug 字段无内容,即使用翻译器对 title 进行翻译
|
|
if (!$topic->slug) {
|
|
$topic->slug = app(SlugTranslateHandler::class)->translate($topic->title);
|
|
}
|
|
}
|
|
|
|
public function updating(Topic $topic)
|
|
{
|
|
//
|
|
}
|
|
} |