Created
May 17, 2016 08:23
-
-
Save Wol/27896d2a14612947adfa3f1e600c2fb7 to your computer and use it in GitHub Desktop.
Add a field to a Stream in PyroCMS 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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