Skip to content

Instantly share code, notes, and snippets.

@franzose
Created October 5, 2013 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franzose/6836910 to your computer and use it in GitHub Desktop.
Save franzose/6836910 to your computer and use it in GitHub Desktop.
`$page = Page::make();` instead of `$page = new Page()`; Then we can set proper position...
public static function make(array $attributes = array())
{
$model = new static();
// Workaround to set the position
if ( ! isset($attributes[static::POSITION]))
{
// We set depth to 0 because newly created model
// via 'create' method has no default closure table
// attributes and is inserted as a root node
$model->hidden[static::DEPTH] = 0;
$attributes[static::POSITION] = $model->guessPositionOnCreate();
}
$model->fill($attributes);
return $model;
}
/**
* Save a new model and return the instance.
*
* @param array $attributes
* @return Entity|static
*/
public static function create(array $attributes)
{
$model = static::make($attributes);
$model->save();
$model->setHidden($model->getClosureAttributes());
return $model;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment