1. Go to this page and download the library: Download anubarak/craft-seeder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anubarak / craft-seeder example snippets
use anubarak\seeder\models\EntryConfig;
use anubarak\seeder\models\FieldCallback;
use anubarak\seeder\models\Settings;
use craft\base\ElementInterface;
use craft\base\FieldInterface;
$config = (new Settings())
->fieldsConfig([
new EntryConfig(
'news',
[
(new FieldCallback('date'))
->setCallable(
static function(
\Faker\Generator $faker,
FieldInterface $field,
ElementInterface $element
) {
return new DateTime();
}
),
(new FieldCallback('date2'))
->setCallable(
static function(
\Faker\Generator $faker,
FieldInterface $field,
ElementInterface $element
) {
$date = (clone $element->getFieldValue('date'));
$date->modify('+1 day');
return $date;
}
),
(new FieldCallback('headline'))
->setFakerMethod('text'),
]
)
]);
//