-
Notifications
You must be signed in to change notification settings - Fork 61
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
adding a fix to support variables as params #85
Conversation
There's now quite some duplication in the try/catch block which makes it hard to see what exactly is being catched. Refactor this so that a variable |
Hi @freekmurze I found a complicate scenario that is why the code is written in this way, with the current code in @inlinedImage('assets/images/logo.png') Works as this code inside the package service provider is getting: Blade::directive('inlinedImage', function ($url) {
dd($url); // returns the string "assets/images/logo.png"
}); But with a variable from a controller or using php directive to set it: @php $image = 'assets/images/logo.png'; @endphp
@inlinedImage($image) It returns the variable name as a string Blade::directive('inlinedImage', function ($url) {
dd($url); // returns the string "$image"
}); I think this is a limitation I think because it is too early in the application lifecycle, so a variable is replaced I think when Blade compiles, that is why I had to set all the code at once. If I set a $content = base64_encode(file_get_contents(asset("$url")));
// or
$content = base64_encode(Http::get("$url")); I think I did not miss anything, I would be looking forward your feedback, and thanks! |
The Last commits make
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add tests for this to ensure that it works correctly?
Hi @freekmurze I know that you are probably a lot more busy, if you have any chance to check these new changes that add tests to generate images for headers and footers please let me know. I am glad to help and if there is any feedback it would be welcome, I let you know how ingenious looks the |
Thanks! I'll check on |
The tests are failing, could you send another PR to fix them? |
What makes this PR
close #84
This does work:
This does NOT work:
As far as I understand any service provider is executed too early in an application lifecycle, so it cannot evaluate a variable value that is set in a controller.
To solve this all the code is now executed at the same time to be executed in the blade file directly.
The solution is probably not so elegant, but solves both cases, static strings and variables as params
Explanation with the solution
https://www.loom.com/share/00cc167045d04310ae194ac2af157d07?sid=a984958f-c830-4077-b263-684eda2378d6
@freekmurze if you can imagine a better solution I would be glad to implement it, thanks