Created
October 5, 2013 05:08
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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