-
app/Observers/CommentObserver.php
Open in GitHubuse App\Models\Comment; use Xetaio\Mentions\Parser\MentionParser; class CommentObserver { public function created(Comment $comment) { $parser = new MentionParser($comment, [ 'regex_replacement' => [ '{character}' => '@', '{pattern}' => '[A-Za-z0-9_-]', '{rules}' => '{4,20}' ], ]); $content = $parser->parse($comment->content); $comment->updateQuietly([ 'content' => $content, ]); } public function deleting(Comment $comment) { $comment->mentions()->delete(); } }
-
app/Providers/EventServiceProvider.php
Open in GitHubuse App\Models\Comment; use App\Observers\CommentObserver; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { // protected $observers = [ // Comment::class => [CommentObserver::class], ]; // }