generate() public method

Automatically generate the attribute we want.
public generate ( string | callable $kind, object $model, FactoryMuffin $factoryMuffin ) : mixed
$kind string | callable The kind of attribute.
$model object The model instance.
$factoryMuffin League\FactoryMuffin\FactoryMuffin The factory muffin instance.
return mixed
Esempio n. 1
0
 /**
  * Generate and set the model attributes.
  *
  * @param object $model The model instance.
  * @param array  $attr  The model attributes.
  *
  * @return void
  */
 protected function generate($model, array $attr = [])
 {
     foreach ($attr as $key => $kind) {
         $value = $this->generatorFactory->generate($kind, $model, $this);
         $setter = 'set' . ucfirst(self::camelize($key));
         // check if there is a setter and use it instead
         if (method_exists($model, $setter)) {
             $model->{$setter}($value);
         } else {
             $model->{$key} = $value;
         }
     }
 }
Esempio n. 2
0
 /**
  * Generate and set the model attributes.
  *
  * @param object $model The model instance.
  * @param array  $attr  The model attributes.
  *
  * @return void
  */
 protected function generate($model, array $attr = [])
 {
     foreach ($attr as $key => $kind) {
         $model->{$key} = $this->generatorFactory->generate($kind, $model, $this);
     }
 }