1. Go to this page and download the library: Download offline/oc-seeder-plugin 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/ */
offline / oc-seeder-plugin example snippets
// plugins/yourvendor/yourplugin/factories/YourModelFactory.php
namespace YourVendor\YourPlugin\Factories;
class YourModelFactory extends \OFFLINE\Seeder\Classes\Factory
{
/**
* Default model attributes.
*/
public function definition()
{
return [
'name' => fake()->name,
'number' => fake()->numberBetween(0, 6),
];
}
/**
* Define states: Override attributes that differ from the default definition.
* Use it like this: YourModel::factory()->withHigherNumber()->make();
*/
public function withHigherNumber()
{
return $this->states(function(array $attributes) {
return [
'number' => fake()->numberBetween(100, 900);
];
});
}
}
// plugins/yourvendor/yourplugin/models/YourModel.php
namespace YourVendor\YourPlugin\Models;
class YourModel extends Model
{
use \OFFLINE\Seeder\Traits\HasSeederFactory; // add this
}
public function registerSeeder()
{
\YourVendor\YourPlugin\Models\YourModel::factory()->count(50)->create();
}
namespace App\Factories\Blog;
class PostFactory extends \OFFLINE\Seeder\Classes\Factory
{
public function definition()
{
return [
'title' => fake()->sentence,
// ...
'is_enabled' => true,
];
}
}
// Old
factory(YourModel::class)->make();
factory(YourModel::class)->states('special')->make();
// New
YourModel::factory()->make();
YourModel::factory()->special()->make();
// Create a model
$myModel = \YourVendor\YourPlugin\Models\YourModel::factory()->create();
// Attach an image
$image = \System\Models\File::factory()->make();
$myModel->image()->save($image);