baum icon indicating copy to clipboard operation
baum copied to clipboard

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

Open j4n4r opened this issue 10 years ago • 2 comments

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]);

j4n4r avatar Apr 17 '15 08:04 j4n4r

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'],
            ]],
        ]],
    ]],
];

j4n4r avatar Apr 19 '15 09:04 j4n4r

Possibly related to or the same as #68

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

jonaholsson avatar Jun 27 '17 19:06 jonaholsson