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

The directive is not compatible with Blade::stringable #7

Open
machacekmartin opened this issue Sep 13, 2024 · 3 comments
Open

The directive is not compatible with Blade::stringable #7

machacekmartin opened this issue Sep 13, 2024 · 3 comments

Comments

@machacekmartin
Copy link

Custom scope directive works as intended until we add our custom configuration of Blade::stringable into AppServiceProvider.

Steps to reproduce

  • Install this package
  • Use the example from the docs
    index.blade.php
@component('components.list', ['objects' => $objects])
    @scopedslot('item', ($object))
        <li>
            {{ $object->name }} 
            @if($object->isEditable)
                <a href="{{ route('objects.edit', $object->id) }}">{{ __('Edit') }}</a>
            @endif
        </li>
    @endscopedslot
@endcomponent

components/list.blade.php

<ul>
    @foreach($objects as $object)
        {{ $item($object) }}
    @endforeach
</ul>
  • No problems so far
  • Register Blade::stringable into your AppServiceProvider using boot method
public function boot(): void
{
    Blade::stringable(function(\Illuminate\Support\Carbon $value) {
        return $value->format('d. m. Y');
    });
}
  • Run php artisan optimize:clear
  • Page now no longer works and an exception is thrown.
Internal Server Error

ErrorException
Undefined variable $__bladeCompiler

I have not found any solution to this problem. Please let me know if you manage to fix it. I want to apply default formatting of dates in blade components, but it seems the custom scope directive is somehow conflicting with it.

@konradkalemba
Copy link
Owner

Hi @machacekmartin, thanks for the detailed report. I fixed it in d66b44a and version 0.1.2. Please update the package and clear the view cache – it should be working now.

machacekmartin added a commit to machacekmartin/mary that referenced this issue Sep 13, 2024
This fixes the Issue of scope directive throwing an exception with Blade::stringable configuration being present in AppServiceProvider.

konradkalemba/blade-components-scoped-slots#7
@machacekmartin
Copy link
Author

machacekmartin commented Sep 13, 2024

I was about to submit a PR that fixes the bug bcs I finally found out where the problem is, but too late, you already published the fix :D thank you!

robsontenorio pushed a commit to robsontenorio/mary that referenced this issue Sep 13, 2024
This fixes the Issue of scope directive throwing an exception with Blade::stringable configuration being present in AppServiceProvider.

konradkalemba/blade-components-scoped-slots#7
@konradkalemba
Copy link
Owner

@machacekmartin I happened to be working on a Laravel project today hence the quick fix. :D

Also, I saw you created a PR for some library, however it may not be sufficient, because, when $__bladeCompiler is undefined (e.g. when you aren't using Blade::stringable) PHP will throw an exception. I've added an extra assignment (d66b44a#diff-dc4533e9cdd82fd75dfdc74283ec5d2bbe050827b0c3d65d9f5c82205f2bc9e9R39) just to make sure it's always defined.

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

2 participants