{"id":28656076,"url":"https://github.com/offline-gmbh/oc-seeder-plugin","last_synced_at":"2025-06-13T08:10:15.964Z","repository":{"id":46586180,"uuid":"284915830","full_name":"OFFLINE-GmbH/oc-seeder-plugin","owner":"OFFLINE-GmbH","description":"Laravel Seeder integration for October CMS","archived":false,"fork":false,"pushed_at":"2024-02-28T07:55:26.000Z","size":27117,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-31T10:26:30.779Z","etag":null,"topics":["factories","laravel-seeder","oc-seeder-plugin","octobercms-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OFFLINE-GmbH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-08-04T08:00:25.000Z","updated_at":"2023-09-03T13:05:48.000Z","dependencies_parsed_at":"2023-11-15T16:37:31.677Z","dependency_job_id":null,"html_url":"https://github.com/OFFLINE-GmbH/oc-seeder-plugin","commit_stats":{"total_commits":43,"total_committers":5,"mean_commits":8.6,"dds":"0.32558139534883723","last_synced_commit":"068db2138bda6b4d83b54597f7a12f03ee99b5a5"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/OFFLINE-GmbH/oc-seeder-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OFFLINE-GmbH%2Foc-seeder-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OFFLINE-GmbH%2Foc-seeder-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OFFLINE-GmbH%2Foc-seeder-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OFFLINE-GmbH%2Foc-seeder-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OFFLINE-GmbH","download_url":"https://codeload.github.com/OFFLINE-GmbH/oc-seeder-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OFFLINE-GmbH%2Foc-seeder-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259606992,"owners_count":22883565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["factories","laravel-seeder","oc-seeder-plugin","octobercms-plugin"],"created_at":"2025-06-13T08:10:14.923Z","updated_at":"2025-06-13T08:10:15.934Z","avatar_url":"https://github.com/OFFLINE-GmbH.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oc-seeder-plugin\n\nLaravel Seeder integration for October CMS.\n\nThis plugin integrates Laravel's Factory and Database Seeder features with October CMS.\n\n## Installation\n\n1. Install the plugin using Composer.\n\n```bash\ncomposer require offline/oc-seeder-plugin\n```\n\n2. Setup the random file helpers.\n\n```bash\nphp artisan seeder:init\n```\n\n## Defining factories\n\nTo define a new Factory for your plugin, create a `YourModelFactory.php` in the plugin's `factories` folder and define\nyour factories [as you would in Laravel](https://laravel.com/docs/9.x/database-testing#defining-model-factories):\n\n```php\n\u003c?php\n// plugins/yourvendor/yourplugin/factories/YourModelFactory.php\nnamespace YourVendor\\YourPlugin\\Factories;\n\nclass YourModelFactory extends \\OFFLINE\\Seeder\\Classes\\Factory\n{\n    /**\n     * Default model attributes.\n     */\n    public function definition()\n    {\n        return [\n            'name' =\u003e fake()-\u003ename,\n            'number' =\u003e fake()-\u003enumberBetween(0, 6),\n        ];\n    }\n\n    /**\n     * Define states: Override attributes that differ from the default definition.\n     * Use it like this: YourModel::factory()-\u003ewithHigherNumber()-\u003emake();\n     */\n    public function withHigherNumber()\n    {\n        return $this-\u003estates(function(array $attributes) {\n            return [\n                'number' =\u003e fake()-\u003enumberBetween(100, 900);\n            ];\n        });\n    }\n}\n\n```\n\n\nNext, add the `OFFLINE\\Seeder\\Traits\\HasSeederFactory` trait to your model:\n\n```php\n\u003c?php\n// plugins/yourvendor/yourplugin/models/YourModel.php\nnamespace YourVendor\\YourPlugin\\Models;\n\nclass YourModel extends Model\n{\n    use \\OFFLINE\\Seeder\\Traits\\HasSeederFactory; // add this\n}\n```\n\n## Defining seeders\n\nAdd a `registerSeeder` method to your `Plugin.php` in which you seed your plugin's models:\n\n```php\npublic function registerSeeder()\n{\n    \\YourVendor\\YourPlugin\\Models\\YourModel::factory()-\u003ecount(50)-\u003ecreate();\n}\n```\n\n## Tailor integration\n\nStarting from version 2.1, this plugin can be used to seed Tailor data.\n\n### Requirements\n\nTo seed Tailor data using this plugin, it is required that all Tailor blueprint handles are in the `SomeSection\\SomeEntity` format, like `Blog\\Post`.\n\n### Defining factories\n\nFor a Tailor entity like `Blog\\Post`, create the file `app/factories/blog/PostFactory.php` and define your factory in it.\n\n```php\n\u003c?php\n\nnamespace App\\Factories\\Blog;\n\nclass PostFactory extends \\OFFLINE\\Seeder\\Classes\\Factory\n{\n    public function definition()\n    {\n        return [\n            'title' =\u003e fake()-\u003esentence,\n            // ...\n            'is_enabled' =\u003e true,\n        ];\n    }\n}\n```\n\n### Registering seeders\n\nIn the `app/Provider.php`, add a static `registerSeeder` method and define your seeders like so:\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse OFFLINE\\Seeder\\Classes\\Factory;\n\nclass Provider extends \\System\\Classes\\AppBase\n{\n    // ...\n\n    /**\n     * @param $seed \\Closure(string $handle, \\Closure(Factory $factory) $callback): void\n     */\n    public static function registerSeeder(\\Closure $seed)\n    {\n        // Blog\\Post = blueprint handle\n        $seed('Blog\\Post', function(Factory $factory) {\n            $factory-\u003ecount(10)-\u003ecreate();\n        });\n\n        $seed('Blog\\Category', function(Factory $factory) {\n            // ...\n        });\n\n        $seed('Blog\\Author', function(Factory $factory) {\n            // ...\n        });\n    }\n```\n\n### Seeding specific blueprints\n\nThe `--plugins` flag can be used to seed specific entities:\n\n```bash\nphp artisan offline:seeder --plugins=Blog\\\\Post\n```\n\n## Migrate from 2.x\n\nOctober 3.3 introduced its own `plugin:seed` Artisan command. To \nresolve this conflict, the Artisan command of this plugin was \nrenamed to `offline:seeder`.\n\nNo special migration work is required, you can just use the new \nArtisan command.\n\n## Migrate from 1.x\n\nTo migrate old seeders from Version 1.0 of this plugin, make the following changes:\n\n1. Move all factories from the `factories.php` to their own `Factory` classes in the `factories` directory.\n2. Add the `OFFLINE\\Seeder\\Traits\\HasSeederFactory` trait to all models\n3. Change your `registerSeeder` method:\n\n```php\n// Old\nfactory(YourModel::class)-\u003emake();\nfactory(YourModel::class)-\u003estates('special')-\u003emake();\n// New\nYourModel::factory()-\u003emake();\nYourModel::factory()-\u003especial()-\u003emake();\n```\n\n## Running seeders\n\nSimply run `php artisan offline:seeder` to run the seeders of all plugins. The seeder of each plugin will be only run once.\n\nTo run a seeder for a already seeded plugin, use the `--fresh` option. Be aware that this will rollback and reinstall\nall plugins with a registered seeder completely, so any plugin data will be lost.\n\nYou can use the `--plugins` option to run only specified seeders. Simply provide a comma-separated list of plugin names.\n\n```\nphp artisan offline:seeder --plugins=Vendor.PluginA,Vendor.PluginB --fresh\n```\n\n## Included factories\n\nThis plugin includes factories for the following models:\n\n### `\\System\\Models\\File::class`\n\n`\\System\\Models\\File::factory()-\u003emake()` returns a `File` model with a random image. You can use it in any seeder\nto attach a file to a created model:\n\n```php\n// Create a model\n$myModel = \\YourVendor\\YourPlugin\\Models\\YourModel::factory()-\u003ecreate();\n\n// Attach an image\n$image = \\System\\Models\\File::factory()-\u003emake();\n$myModel-\u003eimage()-\u003esave($image);\n```\n\nThere are size states available: `tiny` returns a `90x90` image, `hd` returns a `1920x1080` image and `huge` returns\na `6000x4000` image.\nOnly one side of the image will match the given dimension (it is uncropped by default).\n\n```php\n$tiny = \\System\\Models\\File::factory()-\u003etiny()-\u003emake();\n$hd = \\System\\Models\\File::factory()-\u003ehd()-\u003emake();\n$huge = \\System\\Models\\File::factory()-\u003ehuge()-\u003emake();\n```\n\nIf you need something other than an image, you can use the `file`, `pdf`, `mp3` or `xlsx` states:\n\n```php\n$randomType = \\System\\Models\\File::factory()-\u003efile()-\u003emake();\n$pdf = \\System\\Models\\File::factory()-\u003epdf()-\u003emake();\n$mp3 = \\System\\Models\\File::factory()-\u003emp3()-\u003emake();\n$xlsx = \\System\\Models\\File::factory()-\u003exlsx()-\u003emake();\n```\n\n### `\\Backend\\Models\\User::class`\n\n`\\Backend\\Models\\User::factory()-\u003emake()` returns a Backend `User` model. You can use the `superuser`\n state to generate a superuser.\n\n```php\n// Build a simple backend user.\n\\Backend\\Models\\User::factory()-\u003emake();\n\n// Build a superuser backend user.\n\\Backend\\Models\\User::factory()-\u003esuperuser()-\u003emake();\n```\n\n### `\\RainLab\\User\\Models\\User::class`\n\n`\\RainLab\\User\\Models\\User::factory()-\u003emake()` returns a RainLab `User` model.\n\n## Twig helper functions\n\nYou can use the `random_image()` helper function to get a random image directly in your markup.\n\n```twig\n\u003cimg src=\"{{ random_image().thumb(400, 800) }}\" alt=\"\"/\u003e\n\u003cimg src=\"{{ random_image('tiny').thumb(400, 800) }}\" alt=\"\"/\u003e\n\u003cimg src=\"{{ random_image('hd').thumb(400, 800) }}\" alt=\"\"/\u003e\n\u003cimg src=\"{{ random_image('huge').thumb(400, 800) }}\" alt=\"\"/\u003e\n```\n\nIf you need a valid file download, you can use the `random_file()` function:\n\n```twig\n\u003ca href=\"{{ random_file('xlsx').path }}\" download\u003eDownload the spreadsheet!\u003c/a\u003e\n\u003ca href=\"{{ random_file('pdf').path }}\" download\u003eDownload the PDF!\u003c/a\u003e\n\n{# or make some noise #}\n\u003caudio controls src=\"{{ random_file('mp3').path }}\"\u003e\u003c/audio\u003e\n```\n\n## Attribution\n\nAll images used in this plugin are provided by [unsplash.com](https://unsplash.com).\n\n## Credits\n\nThis plugin is heavily inspired by [Inetis' oc-testing-plugin](https://github.com/inetis-ch/oc-testing-plugin).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffline-gmbh%2Foc-seeder-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foffline-gmbh%2Foc-seeder-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffline-gmbh%2Foc-seeder-plugin/lists"}