Skip to content

Instantly share code, notes, and snippets.

@jaggy
Last active February 26, 2016 10:57
Show Gist options
  • Save jaggy/a4791a3ffc21ebdea0b5 to your computer and use it in GitHub Desktop.
Save jaggy/a4791a3ffc21ebdea0b5 to your computer and use it in GitHub Desktop.
<?php
function createAccountFor($type, $name = null, $model) {
$parameters = [
'name' => $name,
'model_id' => $model->id,
];
return factory(Account::class, $type)->create($parameters);
}
// Usage
$jaggy = $this->createClient('Jaggy');
$typekit = $this->createAccountFor('client', 'Typekit', $jaggy);
<?php
function createAccountFor($model, $name = null, ) {
$parameters = [
'name' => $name,
'model_id' => $model->id,
];
$type = strtolower(str_replace("App\\", '', get_class($model)));
return factory(Account::class, $type)->create($parameters);
}
// Usage
$jaggy = $this->createClient('Jaggy');
$typekit = $this->createAccountFor($jaggy, 'Typekit');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment