You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I newbie for October CMS, currently I trying make seeder file for data. Can someone guide a sample code for many data with translate on seeder file?
The "title" will have translate to English and Chinese version, when I run "php artisan october:migrate" will show error : "Unexpected type of array when attempting to save attribute "title", try adding it to the $jsonable property.".
But when I add "title" for $jsonable the data will store as array on Model and "rainlab_translate_attributes" didn't have record.
Below is sample code I trying:
<?php namespace App\Test\Updates;
use Seeder;
use App\Test\Models\Resource;
use System\Models\File;
class SeedResourcesTable extends Seeder
{
public function Run()
{
$resources = [
[
'title' => ['en' => 'This is English version',
'cn' => 'This is Chinese version'],
'sources' => json_decode('[{"author":"ABCD","year":"2020"}]'),
'isActive' => 1,
'source_file' => ['Resources1.pdf']
]
];
foreach ($resources as $resource) {
$model = Resource::create($resource);
$model['sort_order'] = $model->getkey();
foreach($resource['source_file'] as $key => $pdf) {
$filePath = "./themes/app/assets/resource/" . $pdf;
if (!file_exists($filePath)) {
echo 'File ' . $filePath . ' not exists.' . "\n";
continue;
}
$file = new File();
$file->fromFile($filePath);
//$file['title'] = $model->title;
//$file['description'] = $model->content['description'];
$model->source_file()->save($file, null);
}
}
}
}
Thank you
The text was updated successfully, but these errors were encountered:
You may need to implement the translateContext() method to get the attributes to save. Take a look at this tutorial for more info: https://www.youtube.com/watch?v=pDr3KAvZY44
Hi, I newbie for October CMS, currently I trying make seeder file for data. Can someone guide a sample code for many data with translate on seeder file?
The "title" will have translate to English and Chinese version, when I run "php artisan october:migrate" will show error : "Unexpected type of array when attempting to save attribute "title", try adding it to the $jsonable property.".
But when I add "title" for $jsonable the data will store as array on Model and "rainlab_translate_attributes" didn't have record.
Below is sample code I trying:
Thank you
The text was updated successfully, but these errors were encountered: