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

Laravel 9.36.3: Illegal offset type in isset or empty #58

Open
mbeckerle-xqueue opened this issue Oct 21, 2022 · 22 comments
Open

Laravel 9.36.3: Illegal offset type in isset or empty #58

mbeckerle-xqueue opened this issue Oct 21, 2022 · 22 comments

Comments

@mbeckerle-xqueue
Copy link

mbeckerle-xqueue commented Oct 21, 2022

Hi,

with an update from Laravel 9.34.0 to 9.36.3 I get this error when creating a view from database: Illegal offset type in isset or empty

I compared the files before and after the update and this is the commit that breaks this project:
laravel/framework@331bf9c

In DbView (https://github.com/Flynsarmy/laravel-db-blade-compiler/blob/master/src/Flynsarmy/DbBladeCompiler/DbView.php) the path is set to be the model: $this->path = $model;

Later the content is set to $this->path->__db_blade_compiler_content_field which is then passed over getContents() to the engine:
$this->engine->get($this->path, $this->gatherData())

Laravels compiler engine expects a string in "public function get($path, array $data = [])" and since that commit they even use that path an array key, which fails in the end, was currently a model is used.

I am not so deep into all the internal template handling, so I hope my findings can at least help you to fix this.

Marcus

@Flynsarmy
Copy link
Owner

If you send a PR I'd be happy to merge :)

@mbeckerle-xqueue
Copy link
Author

Hi,

unfortunately I only found the source of the problem but I do not know how to solve it in a correct way so it still / again works.
I was hoping you see the above information and have already a solution in your mind, once you are done reading :D

@hoekie
Copy link

hoekie commented Oct 23, 2022

Hi,
I've the same problem after an update to laravel 9.36.3: Illegal offset type in isset or empty.
Unfortunately, I don't have the knowledge to solve this...

Please, can you give us a solution to this?

Thanks in advance.

Richard

@mbeckerle-xqueue
Copy link
Author

Just for your information: I temporarily "solved" this by fixing my Laravel Framework to the latest 9.35 version

"laravel/framework": "9.35.1",

The critical commit was added in the first 9.36 release. Unfortunately I also have not really found a solution, so I hope for @Flynsarmy to better understand how it should be right.

@hoekie
Copy link

hoekie commented Oct 24, 2022

Hi @mbeckerle-xqueue,

I will try this in a couple of days...
Thanks for your comment on this!

I hope it will be fixed soon.

Thanks!

Richard

@sagarsoani
Copy link

sagarsoani commented Nov 21, 2022

Is this issue solved ? i found this also on this 9.40.1 version. @Flynsarmy @hoekie

@Marcel-Sass
Copy link

i can propose a quickfix for someone to include in this package:

in Flynsarmy/DbBladeCompiler/DbBladeCompilerEngine.php add

/**
     * @param string $compiled_path
     * @param array $data
     * @return string
     */
    public function getContent(string $compiled_path, array $data)
    {
        return $this->evaluatePath($compiled_path, $data);
    }

and update \Flynsarmy\DbBladeCompiler\DbView::getContents to

protected function getContents()
    {
        $field = $this->config->get('db-blade-compiler.model_property');
        $this->path->{$field} = $this->content_field;
        $compiler = $this->engine->getCompiler();
        $compiler->compile($this->path);

        return $this->engine->getContent($compiler->getCompiledPath($this->path), $this->data);
    }

maybe this could be improved but it works for now

@hoekie
Copy link

hoekie commented Dec 12, 2022

Cool! Thanks @Marcel-Sass

I will try this in the next few days!

@devansh-webkul
Copy link

devansh-webkul commented Dec 15, 2022

Is anyone fixing this, otherwise we have no option we need to remove the dependency?

Because we need to update the dependencies for our users.

@amouchaldev
Copy link

No Solution Until Now ??

@adityaerlangga
Copy link

adityaerlangga commented Dec 24, 2022

I'm fixing it with change laravel version to "laravel/framework": "9.35.1" in your_app_name/composer.json and changing APP_URL in .env from APP_URL=http://localhost:8000 to APP_URL=http://127.0.0.1:8000. Might this help you all

@RamceI
Copy link

RamceI commented Dec 27, 2022

The problem is with the path src/Illuminate/View/Engines/CompilerEngine.php in the function get() line 61 inside
if(!isset($this->compiledOrNotExpired[$path])) the variable $path is not sent as an array but full path and that's why it can't produce an array.

As solved is if(!isset($path))

@mrtsven
Copy link

mrtsven commented Jan 3, 2023

Hey for everyone trying to render blade, you could use: https://laravel.com/docs/9.x/blade#rendering-inline-blade-templates
Hopefully this helps!

@zfhassaan
Copy link
Contributor

i can propose a quickfix for someone to include in this package:

in Flynsarmy/DbBladeCompiler/DbBladeCompilerEngine.php add

/**
     * @param string $compiled_path
     * @param array $data
     * @return string
     */
    public function getContent(string $compiled_path, array $data)
    {
        return $this->evaluatePath($compiled_path, $data);
    }

and update \Flynsarmy\DbBladeCompiler\DbView::getContents to

protected function getContents()
    {
        $field = $this->config->get('db-blade-compiler.model_property');
        $this->path->{$field} = $this->content_field;
        $compiler = $this->engine->getCompiler();
        $compiler->compile($this->path);

        return $this->engine->getContent($compiler->getCompiledPath($this->path), $this->data);
    }

maybe this could be improved but it works for now

Thank you for sharing. It solved the issue.

@Flynsarmy
Copy link
Owner

It looks like you closed the PR. Was there a problem with it?

Flynsarmy added a commit that referenced this issue Feb 17, 2023
@Flynsarmy
Copy link
Owner

If someone could test and confirm the issue is now fixed I'll close this issue.

@edwinricaurte
Copy link

I'm getting an error on Laravel 10 (using @section)

error

@edwinricaurte
Copy link

The only quick solution for this specific issue on Laravel 10, is adding the View Factory class to the data variable on

vendor/flynsarmy/db-blade-compiler/src/Flynsarmy/DbBladeCompiler/DbBladeCompilerEngine.php

public function getContent(string $compiled_path, array $data)
{
$data['__env'] = app(\Illuminate\View\Factory::class);
return $this->evaluatePath($compiled_path, $data);
}

And updating function getContents() on the the file (@Marcel-Sass suggestion):

vendor/flynsarmy/db-blade-compiler/src/Flynsarmy/DbBladeCompiler/DbView.php

protected function getContents()
{
$field = $this->config->get('db-blade-compiler.model_property');
$this->path->{$field} = $this->content_field;
$compiler = $this->engine->getCompiler();
$compiler->compile($this->path);

 return $this->engine->getContent($compiler->getCompiledPath($this->path), $this->data);

}

Screenshot 2023-04-13 at 1 54 43 PM

@bastos71
Copy link

Could you please publish a new release with the fix merged in master ? thx !

@Flynsarmy
Copy link
Owner

It sounds like there's an issue on Laravel 10 (latest version). That'll need to get fixed before I'll make a new release. If someone wants to send a PR I'll merge.

@bastos71
Copy link

The package does not work with Laravel 9 & Laravel 10 for now
At least the last commit on master makes it compatible with Laravel 9 (wich is my use case, and I assume for others as well), it would be great to publish a release that fixes at least half of the problem 🙂

@Flynsarmy
Copy link
Owner

Done

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