Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createFromArray #244

Open
mefenlon opened this issue Feb 1, 2021 · 0 comments
Open

createFromArray #244

mefenlon opened this issue Feb 1, 2021 · 0 comments

Comments

@mefenlon
Copy link

mefenlon commented Feb 1, 2021

Using
"franzose/closure-table": "^6.1",
"laravel/framework": "^6.2",

When using demo code from https://github.com/franzose/ClosureTable#tree

class SubjectsTableSeeder extends Seeder

{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Subject::createFromArray([
            'id' => 1,
            'children' => [
                [
                    'id' => 2,
                    'children' => [
                        [
                            'id' => 3,
                            'children' => [
                                [
                                    'id' => 4,
                                    'children' => [
                                        [
                                            'id' => 5,
                                            'children' => [
                                                [
                                                    'id' => 6,
                                                ]
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]);
    }

Running the seeder results in this error
In Entity.php line 116:
Argument 1 passed to Franzose\ClosureTable\Models\Entity::__construct() must be of the type array, int given, called in /home/vagrant/code/ripm_lill_laravel/vendor/franzose/closure-table/src/Models/Entity.php on line 1770

After adding another level of nesting as suggested in #239

       Subject::createFromArray([
            [
                'id' => 1,
                'children' => [
                    [
                        'id' => 2,
                        'children' => [
                            [
                                'id' => 3,
                                'children' => [
                                    [
                                        'id' => 4,
                                        'children' => [
                                            [
                                                'id' => 5,
                                                'children' => [
                                                    [
                                                        'id' => 6,
                                                    ]
                                                ]
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]);

I get the error

In Str.php line 419:
Array to string conversion

I believe this issue is related to the nested children. Removing any 'children' results in a successful migration.

        Subject::createFromArray([

                ['id' => 200],
                ['id' => 300],
                ['id' => 400],
                ['id' => 500],

        ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant