public function testBuildMethodThroughFacade() { $this->assertEquals('the_show_must_go_on', Slug::build('The Show Must Go On', '_')); $this->assertEquals('ничего_на_свете_лучше_нету', Slug::build('Ничего на свете лучше нету', '_', 1, false)); $this->assertEquals('чем-бродить-друзьям-по-белу-свету', Slug::build('Чем бродить друзьям по белу свету', '-', 1, false)); $this->assertEquals('Тем_кто_дружен', Slug::build('Тем, кто дружен', '_', 1, true)); $this->assertEquals('Ne-strashny-trevogi', Slug::build('Не страшны тревоги...', '-', 2, true)); $this->assertEquals('nam_lyubye_dorogi_dorogi', Slug::build('Нам любые дороги дороги!', '_', 2, false)); }
/** * Create or recreate slugs in a column. * * @param $fromColumn Column to work with. String from this column will be converted to a slug. * @param bool $force When true, forces recreation of a slug, even if it exists. * @return $this */ public function reslug($fromColumn = false, $force = false) { $slugColumn = config('seoslug.slugColumnName'); if ($fromColumn === false) { $fromColumn = $this->slugFrom; } // If slug needs to be created or recreated if (empty($this->{$slugColumn}) || $force) { $this->{$slugColumn} = \Slug::build($this->{$fromColumn}); } return $this; }
/** * Execute the console command. * * @return mixed */ public function handle() { $table = $this->argument('table'); $column = $this->argument('column'); try { $allRows = \DB::table($table)->select($column)->get(); foreach ($allRows as $row) { \DB::table($table)->where($column, $row->{$column})->update([config('seoslug.slugColumnName') => \Slug::build($row->{$column})]); } } catch (Exception $e) { $this->error($e->getMessage()); } $this->info('Table ' . $table . 'has been reslugged successfully'); }