Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Last active August 30, 2017 03:28
Show Gist options
  • Select an option

  • Save inxilpro/5f11d9a07309f222d9392cb5d31df50d to your computer and use it in GitHub Desktop.

Select an option

Save inxilpro/5f11d9a07309f222d9392cb5d31df50d to your computer and use it in GitHub Desktop.
<?php
// these are the same…
public function create(array $attributes = [])
{
$instance = $this->newModelInstance($attributes);
$instance->save();
return $instance;
}
// and…
public function create(array $attributes = [])
{
return tap($this->newModelInstance($attributes), function ($instance) {
$instance->save(); // some prefer this, as it's all a single, separate block
});
}
// and (in 5.4)…
public function create(array $attributes = [])
{
return tap($this->newModelInstance($attributes))->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment