<?php use Flarum\Event\ConfigureClientView; use Flarum\Event\DiscussionWillBeSaved; use Flarum\Event\ExtensionWasEnabled; use Flarum\Extension\Extension; use Illuminate\Contracts\Events\Dispatcher; return function (Dispatcher $events) { $events->listen(ConfigureClientView::class, function (ConfigureClientView $event) { $event->addAssets(__DIR__ . '/js/lib/string.js'); }); $events->listen(DiscussionWillBeSaved::class, function (DiscussionWillBeSaved $event) { $text = $event->discussion->title; // $slugtify = new \Cocur\Slugify\Slugify(); // $text = $slugtify->slugify($text); $text = \VuThaiHoc\FlarumVnSlug\Utils::genSlug($text); $event->discussion->slug = $text; }); };
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; return ['up' => function (Builder $schema) { $schema->getConnection()->table('discussions')->chunk(100, function ($discussions) use($schema) { foreach ($discussions as $discussion) { $schema->getConnection()->table('discussions')->where('id', $discussion->id)->update(['slug' => \VuThaiHoc\FlarumVnSlug\Utils::genSlug($discussion->title)]); } }); }, 'down' => function (Builder $schema) { $schema->getConnection()->table('discussions')->chunk(100, function ($discussions) use($schema) { foreach ($discussions as $discussion) { $schema->getConnection()->table('discussions')->where('id', $discussion->id)->update(['slug' => Str::slug($discussion->title)]); } }); }];