Skip to content

Instantly share code, notes, and snippets.

@Wol
Created May 17, 2016 08:23
Show Gist options
  • Save Wol/27896d2a14612947adfa3f1e600c2fb7 to your computer and use it in GitHub Desktop.
Save Wol/27896d2a14612947adfa3f1e600c2fb7 to your computer and use it in GitHub Desktop.
Add a field to a Stream in PyroCMS 3
<?php
use Anomaly\Streams\Platform\Database\Migration\Migration;
class MyprojectModuleIndividualsAddSlugField extends Migration
{
/* Define the new field, and field config here */
protected $fields = [
'slug' => [
'type' => 'anomaly.field_type.slug',
'config' => [
'type' => '-',
'slugify' => 'name'
]
]
];
/* Choose which stream this is being applied to */
protected $stream = [
'slug' => 'individuals'
];
/* Define the stream assignments */
protected $assignments = [
'slug' => ['required' => 'true'],
];
/* Do any processing on existing entries if needed */
public function up()
{
$individuals = \Myproject\IndividualsModule\Individual\IndividualModel::all();
foreach($individuals as $individual){
$individual->slug = str_replace(" ", "-", strtolower($individual->name));
$individual->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment