etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 460 forks source link

How to set "scope" only once when mass assigning from array? #160

Open janareit opened 9 years ago

janareit commented 9 years ago

Hey! Is there a way to set this 'company_id' only once when building from array?

Seems a bit annoying to duplicate it to every array element when mass assigning with Category::buildTree($categories)

$root1 = Category::create(['name' => 'Root', 'company_id' => 1]);
$root2 = Category::create(['name' => 'Root', 'company_id' => 1]);

$child1 = Category::create(['name' => 'Child', 'company_id' => 1]);
$child2 = Category::create(['name' => 'Child', 'company_id' => 1]);
janareit commented 9 years ago

Same question also when mass assigning from array? It would be nice if I could pass my scopes array to BuildTree method.

Just to avoid adding keys to every line in array...

$categories = [
    ['family_id' => 1, 'name' => 'Category', 'children' => [
        ['family_id' => 1, 'name' => 'Category2', 'children' => [
            ['family_id' => 1, 'name' => 'Category3', 'children' => [
                ['family_id' => 1, 'name' => 'Category4'],
                ['family_id' => 1, 'name' => 'Category5'],
            ]],
        ]],
    ]],
];
jonaholsson commented 7 years ago

Possibly related to or the same as #68

Not sure if this project is alive though.. @etrepat?