Skip to content

Instantly share code, notes, and snippets.

@ChVuagniaux
Created May 1, 2018 13:39
Show Gist options
  • Save ChVuagniaux/1126b4eee1a6cdd4b42f3605dd0fabec to your computer and use it in GitHub Desktop.
Save ChVuagniaux/1126b4eee1a6cdd4b42f3605dd0fabec to your computer and use it in GitHub Desktop.
RainLab - Generate indexed attribute for existring translations
<?php
/*
*
* Generate RainLab translation index
* @see https://github.com/rainlab/translate-plugin#indexed-attributes
*
*/
Route::get('generate', function () {
$items = DB::table('rainlab_translate_attributes')
->where('model_type', 'Inetis\YOUR_PLUGIN\Models\YOUR_MODEL')
->get();
$attribute = 'name';
$items->each(function ($item) use ($attribute) {
$data = json_decode($item->attribute_data);
if (empty($data->{$attribute})) {
return;
}
DB::insert('INSERT INTO rainlab_translate_indexes (locale, model_id, model_type, item, `value`) VALUES (?, ?, ?, ?, ?)',
[
$item->locale,
$item->model_id,
$item->model_type,
$attribute,
$data->{$attribute},
]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment