mattstauffer / Torch

Examples of using each Illuminate component in non-Laravel applications
MIT License
1.85k stars 211 forks source link

Anonymous Balde X components not working #174

Closed lexdubyna closed 3 years ago

lexdubyna commented 3 years ago

Hello. I am running components/view as it is mentioned here https://github.com/mattstauffer/Torch/tree/master/components/view#usage, but when I try adding anonymous component, I get an error.

Updated templates/page.blade.php:

@extends('layout')

@section('content')

    <h1>{{ $title }}</h1>
    <p>{{ $text }}</p>

    <x-alert type="success" message="Good luck!" />

@endsection

The templates/components/alert.blade.php:

@props([
    'type' => 'info',
    'message'
])

<div {{ $attributes->merge(['class' => 'alert alert-' . $type]) }}>
    {{ $message }}
</div>

The error:

Illuminate\Contracts\Container\BindingResolutionException thrown with message 
"Target [Illuminate\Contracts\View\Factory] is not instantiable."

Stacktrace:
#33 Illuminate\Contracts\Container\BindingResolutionException in 
C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:1017
#32 Illuminate\Container\Container:notInstantiable in 
C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:818
#31 Illuminate\Container\Container:build in C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:691
#30 Illuminate\Container\Container:resolve in C:\OpenServer\domains\view\vendor\illuminate\container\Container.php:637
#29 Illuminate\Container\Container:make in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:221
#28 Illuminate\View\Compilers\ComponentTagCompiler:componentClass in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:185
#27 Illuminate\View\Compilers\ComponentTagCompiler:componentString in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:170
#26 Illuminate\View\Compilers\ComponentTagCompiler:Illuminate\View\Compilers\{closure} in [internal]:0
#25 preg_replace_callback in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:165
#24 Illuminate\View\Compilers\ComponentTagCompiler:compileSelfClosingTags in             
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:79
#23 Illuminate\View\Compilers\ComponentTagCompiler:compileTags in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\ComponentTagCompiler.php:66
#22 Illuminate\View\Compilers\ComponentTagCompiler:compile in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\BladeCompiler.php:322
#21 Illuminate\View\Compilers\BladeCompiler:compileComponentTags in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\BladeCompiler.php:222
#20 Illuminate\View\Compilers\BladeCompiler:compileString in 
C:\OpenServer\domains\view\vendor\illuminate\view\Compilers\BladeCompiler.php:143
#19 Illuminate\View\Compilers\BladeCompiler:compile in 
C:\OpenServer\domains\view\vendor\illuminate\view\Engines\CompilerEngine.php:51
#18 Illuminate\View\Engines\CompilerEngine:get in C:\OpenServer\domains\view\vendor\illuminate\view\View.php:139
#17 Illuminate\View\View:getContents in C:\OpenServer\domains\view\vendor\illuminate\view\View.php:122
#16 Illuminate\View\View:renderContents in C:\OpenServer\domains\view\vendor\illuminate\view\View.php:91
#15 Illuminate\View\View:render in C:\OpenServer\domains\view\index.php:57
#14 Closure:{closure} in C:\OpenServer\domains\view\vendor\slim\slim\Slim\Handlers\Strategies\RequestResponse.php:40
#13 call_user_func in C:\OpenServer\domains\view\vendor\slim\slim\Slim\Handlers\Strategies\RequestResponse.php:40
#12 Slim\Handlers\Strategies\RequestResponse:__invoke in 
C:\OpenServer\domains\view\vendor\slim\slim\Slim\Route.php:281
#11 Slim\Route:__invoke in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:117
#10 Slim\Route:callMiddlewareStack in C:\OpenServer\domains\view\vendor\slim\slim\Slim\Route.php:268
#9 Slim\Route:run in C:\OpenServer\domains\view\vendor\slim\slim\Slim\App.php:503
#8 Slim\App:__invoke in C:\OpenServer\domains\view\vendor\zeuxisoo\slim- 
whoops\src\Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware.php:31
#7 Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware:__invoke in 
C:\OpenServer\domains\view\vendor\slim\slim\Slim\DeferredCallable.php:57
#6 call_user_func_array in C:\OpenServer\domains\view\vendor\slim\slim\Slim\DeferredCallable.php:57
#5 Slim\DeferredCallable:__invoke in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:70
#4 call_user_func in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:70
#3 Slim\App:Slim\{closure} in C:\OpenServer\domains\view\vendor\slim\slim\Slim\MiddlewareAwareTrait.php:117
#2 Slim\App:callMiddlewareStack in C:\OpenServer\domains\view\vendor\slim\slim\Slim\App.php:392
#1 Slim\App:process in C:\OpenServer\domains\view\vendor\slim\slim\Slim\App.php:297
#0 Slim\App:run in C:\OpenServer\domains\view\index.php:60

Please help.

Gummibeer commented 3 years ago

Will check this out now.

borvelt commented 3 years ago

Hello I'm still having this issue. the same error without whoops middleware. have I missed anything?

Gummibeer commented 3 years ago

@borvelt I will check again but it worked on my end. If it doesn't work for you could you try to alias the view to the named interface? I'm not on PC right now - will send you the exact line later if needed.

Gummibeer commented 3 years ago

184 will fix it finally - seems like I've forgotten a final test run or whatever happened.

An alias was missing as the view factory binding is used both ways.

Personally I hate these double bindings to string literals. 🤯

borvelt commented 3 years ago

Great! I'm not professional in PHP and I just changed index.php:L40 to $container->instance(\Illuminate\Contracts\View\Factory::class, $viewFactory); and I got Object Reflection error but sth rendered in my compiled folder. Thanks for your new PL.

Gummibeer commented 3 years ago

Does it work with my PR changes for you? I was able to reproduce but after these changes it's gone.

borvelt commented 3 years ago

Yeah, everything works fine.