Comments (14)
I've found a much quicker way to achieve this basically with no coding at all.
config(['sluggable.onUpdate' => true]);
Model::all()->each->save();
from eloquent-sluggable.
I created a pull request for this: #77
from eloquent-sluggable.
👍
Works great, A++, would merge. :)
from eloquent-sluggable.
Please do ! just found the need myself :) 👍
from eloquent-sluggable.
Sorry I never responded to this sooner. If you still need this, and the master
branch can't do it for you, please submit an MR again and I'll add it.
from eloquent-sluggable.
I found that this problem has been solved. What command should I use in order to create slugs for preexisting records?
from eloquent-sluggable.
First you need to copy this file over:
Then to run you do slugs:create ModelName
. You can also add in the --force
flag if you want to overwrite existing slugs.
Was planning to create a new pull request for this but never got around to it.
from eloquent-sluggable.
Thank you very much. In laravel 5, in order to run the command, you have to write the model prefixed by its namespace
php artisan slugs:create App\Course
from eloquent-sluggable.
Has this been merged into the master branch? It'd be rather handy to batch create the slugs for existing table rows and a seemingly important feature
from eloquent-sluggable.
@kenmoini: I don't think it has. I haven't used Laravel in ages. At work now but I'll try to clean up the code a bit and submit a new pull request when I get home.
from eloquent-sluggable.
Another pull request created. Please merge: #208
from eloquent-sluggable.
Working with Laravel 5.5. You have to place it in App\Console and include it in the $commands array in Kernel.php
<?php namespace App\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use \Cviebrock\EloquentSluggable\Services\SlugService;
class CreateSlugsCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'slugs:create';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create slugs for Model.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$model_name = ucfirst($this->argument('model'));
$model = new $model_name;
try
{
$model = new $model_name;
}
catch(Exception $e)
{
$this->error('The model was not found');
}
$result = $model::all();
foreach($result as $item) {
$field = $item->sluggable()['slug']['source'];
$slug = SlugService::createSlug($model, 'slug', $item->$field);
$item->slug = $slug;
$item->save();
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('model', InputArgument::REQUIRED, 'The model you want to update the slugs for.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('force', null, InputOption::VALUE_NONE, 'Overwrite existing slugs.', null),
);
}
}
from eloquent-sluggable.
I use migrations to do the same thing, it is somehow cleaner and also does not pollute your commands since you will most likely run it only once to catch up with missing slugs for a model.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;
use App\Classified;
class GenerateSlugs extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$classifieds = Classified::all();
$output = new ConsoleOutput();
error_log('Fixing missing slugs');
$bar = new ProgressBar($output, count($classifieds));
foreach ($classifieds as $classified) {
$bar->advance();
$classified->save();
}
$bar->finish();
error_log("\n");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
from eloquent-sluggable.
This feature is hidden, is not in the doc
from eloquent-sluggable.
Related Issues (20)
- Slug still duplicated when generate new one with exact same title HOT 3
- Polymorphic One-to-One (Question) HOT 1
- Conditionally force new slug HOT 4
- slug another language HOT 1
- Checking the pull request HOT 1
- Sluggable HOT 1
- throw new \UnexpectedValueException HOT 2
- Я
- Laravel 10 support HOT 8
- Laravel 10 Install issue... HOT 1
- Should findBySlugOrFail return Model instead? HOT 1
- Issue when testing a model factory using make() HOT 3
- Turkish character slug problem
- Slugging behavior when creating a new model varies depending on onUpdate setting HOT 4
- Is it possible to use the slug as source? HOT 4
- SluggableScopeHelpers Trait: Support for orWhere and whereIn HOT 1
- Slugging with Laravel Nova HOT 4
- Remove HTML Tags Before Creating Slug HOT 3
- Bug when using $with properties that include belongTo relationships HOT 7
- Case-sensitivity and slug uniqueness HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eloquent-sluggable.