Skip to content

Instantly share code, notes, and snippets.

Avatar

Yan Ivanov franzose

View GitHub Profile
@franzose
franzose / gist:6837241
Created Oct 5, 2013
in app/routes.php
View gist:6837241
// everything's creating fine. Positions and closure table, all's fine.
$Test = Test::create(array());
$child1 = $Test->appendChild(Test::make(), 0, true);
$child2 = $Test->appendChild(Test::make(), 1, true);
$child3 = $Test->appendChild(Test::make(), 2, true);
$child4 = $Test->appendChild(Test::make(), 3, true);
// this returns ids of $Test, $child1, $child2 and $child3...
dd($child4->prevSiblings()->lists('id'));
@franzose
franzose / gist:6836910
Created Oct 5, 2013
`$page = Page::make();` instead of `$page = new Page()`; Then we can set proper position...
View gist:6836910
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