PHP code example of goldfinch / mill
1. Go to this page and download the library: Download goldfinch/mill 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/ */
goldfinch / mill example snippets
namespace App\Mills;
use Goldfinch\Mill\Mill;
class ArticleMill extends Mill
{
public function factory(): array
{
return [
'Title' => $this->faker->catchPhrase(),
'Summary' => $this->faker->sentence(200),
'Content' => $this->faker->paragraph(10),
'Date' => $this->faker->dateTimeBetween('-8 week')->format('Y-m-d H:i:s'),
'Publisher' => $this->faker->name(),
'Email' => $this->faker->email(),
'Phone' => $this->faker->e164PhoneNumber(),
'Address' => $this->faker->address(),
'Country' => $this->faker->country(),
];
}
}
namespace App\Models;
use SilverStripe\ORM\DataObject;
use Goldfinch\Mill\Traits\Millable;
class Article extends DataObject
{
use Millable;
private static $db = [
'Title' => 'Varchar',
'Summary' => 'Text',
'Content' => 'HTMLText',
'Date' => 'Datetime',
'Publisher' => 'Varchar',
'Email' => 'Varchar',
'Phone' => 'Varchar',
'Address' => 'Varchar',
'Country' => 'Varchar',
];
// ..
}
App\Models\Article::mill(10)->make();
App\Models\Article::mill(1)->make([
'Title' => 'Custom article title',
'Content' => 'Custom text',
]);
App\Models\Article::mill(10)
->make()
->each(function ($item) {
$categories = App\Models\ArticleCategory::get()->shuffle()->limit(rand(0, 4));
foreach ($categories as $category) {
$item->Categories()->add($category);
}
});
bash
php taz make:mill