Skip to content

Instantly share code, notes, and snippets.

View franzose's full-sized avatar

Yan Ivanov franzose

View GitHub Profile
@franzose
franzose / gist:6837241
Created October 5, 2013 05:58
in app/routes.php
// 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 October 5, 2013 05:08
`$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