PHP code example of stephanecoinon / object-factory
1. Go to this page and download the library: Download stephanecoinon/object-factory 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/ */
stephanecoinon / object-factory example snippets
// /app/Popo.php
namespace App;
use StephaneCoinon\ObjectFactory\BuiltByFactory;
/**
* This is a plain old PHP class, we do not extend Eloquent.
*/
class Popo
{
use BuiltByFactory;
/**
* Objects built by model factory are constructed from an array of
* attributes.
*
* Here's an example of implementation.
*
* @param array $attributes
* @return static
*/
public function __construct($attributes = [])
{
foreach ($attributes as $key => $value) {
$this->$key = $value;
}
}
}
// /database/factories/PopoFactory.php
use Faker\Generator as Faker;
$factory->define(App\Popo::class, function (Faker $faker) {
return [
'name' => $faker->name,
];
});
// A single instance
$object = factory(App\Popo::class)->make();
// Or a collection
$objects = factory(App\Popo::class, 3)->make();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.