whitecube / nova-flexible-content

Flexible Content & Repeater Fields for Laravel Nova
MIT License
789 stars 229 forks source link

Layout render in browser but tests fail #195

Open martin-ro opened 4 years ago

martin-ro commented 4 years ago

I have some custom layouts and include them dynamically in a view like this:

pages/show.blade.php

@extends('app')

@section('content')

        @foreach($page->flexible('content') as $block)

            @if(View::exists('components.flexible-content.' . $block->name()))

                @include('components.flexible-content.' . $block->name())

            @else

                <p>View not found.</p>

            @endif

        @endforeach

@endsection

The included layout blocks render just fine in the browser and everything works. But running my tests the foreach fails.

Example test that fails:

/** @test */
    public function page_can_be_called_by_its_slug()
    {
        $this->withoutExceptionHandling();

        $page = factory(Page::class)->create([
            'slug' => 'lorem-ipsum',
            'content' => '',
        ]);

        $this->get('lorem-ipsum')->assertStatus(200);
    }

Excerpt from the error:

ErrorException : Invalid argument supplied for foreach() (View: /Users/mbp/Projects/xxx/resources/views/pages/show.blade.php)
 /Users/mbp/Projects/xxx/storage/framework/views/e872f9a3ed19031837ed98ad092a40ed5ce458aa.php:6
...
...

The view e872f9a3ed19031837ed98ad092a40ed5ce458aa.php:

<?php $__env->startSection('content'); ?>

        <?php $__currentLoopData = $page->flexible('content'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $block): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

            <?php if(View::exists('components.flexible-content.' . $block->name())): ?>

                <?php echo $__env->make('components.flexible-content.' . $block->name(), \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

            <?php else: ?>

                <p>View not found.</p>

            <?php endif; ?>

        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Users/martin/Projects/triplec/resources/views/pages/show.blade.php ENDPATH**/ ?>

It's strange since it actually works manually testing. Any help would much appreciated.

toonvandenbos commented 4 years ago

Hi @martin-ro,

Are you sure you're showing the right view file? There is no foreach statement on line 6 of the compiled view.

Did you try to add info([$page->flexible('content')]) before the loop, then run the tests? My guess is it's returning NULL when in your test environment. This could be linked to the fact that the HasFlexible trait does not cast the flexible value when NovaServiceProvider has not been loaded.

martin-ro commented 4 years ago

Hi @Nyratas,

The wrong line must be because I fiddled around with it while writing the issue. Just ran the test again and shows the right line where the loop starts.

Yes, it's the correct view. Tested with dd($page->flexible('content')). Which returns the test content like

array:1 [
  0 => "[{"layout":".......}]"
]

so I assume it's casted correctly. I also test Nova resources elsewhere so the NovaServiceProvider should be loaded.

The info([$page->flexible('content')]) did not return anything return null.

I kinda run out of ideas whats going on here.

toonvandenbos commented 4 years ago

The dd() seems to return a string... Which should not be the case. Instead, you should have a Collection of Layout objects if the field's content has been parsed correctly.

Could you check what the following line shows in your tests ?

dd(app()->getProvider(\Laravel\Nova\NovaServiceProvider::class));
martin-ro commented 4 years ago

Hi, thanks for helping out. Yes, in browser I do get the collection of layouts. In the test this array of strings.

Here is the out put:

Laravel\Nova\NovaServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/nova/src/NovaServiceProvider.php#L14\^]8;;\ {#239
  #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564
    #basePath: "/Users/mbp/Projects/x"
    #hasBeenBootstrapped: true
    #booted: true
    #bootingCallbacks: array:1 [
      0 => Closure()]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L764\^]8;;\ {#222
        class: "]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\Illuminate\Foundation\Application]8;;\"
        this: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
        use: { …1}
        file: "]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L764\./vendor/laravel/framework/src/Illuminate/Foundation/Application.php]8;;\"
        line: "764 to 766"
      }
    ]
    #bootedCallbacks: array:4 [
      0 => Closure()]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php#L88\^]8;;\ {#36
        class: "]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php#L20\Illuminate\Foundation\Console\Kernel]8;;\"
        this: App\Console\Kernel]8;;file:///Users/mbp/Projects/x/app/Console/Kernel.php#L8\^]8;;\ {#35
          #commands: []
          #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
          #events: Illuminate\Events\Dispatcher]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php#L17\^]8;;\ {#33
            #container: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
            #listeners: array:12 [ …12]
            #wildcards: []
            #wildcardsCache: array:37 [ …37]
            #queueResolver: Closure()]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Events/EventServiceProvider.php#L18\^]8;;\ {#34 …5}
          }
          #artisan: null
          #commandsLoaded: true
          #bootstrappers: array:7 [ …7]
        }
        file: "]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php#L88\./vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php]8;;\"
        line: "88 to 90"
      }
      1 => Closure()]8;;file:///Users/mbp/Projects/x/vendor/ebess/advanced-nova-media-library/src/AdvancedNovaMediaLibraryServiceProvider.php#L18\^]8;;\ {#198
        class: "]8;;file:///Users/mbp/Projects/x/vendor/ebess/advanced-nova-media-library/src/AdvancedNovaMediaLibraryServiceProvider.php#L10\Ebess\AdvancedNovaMediaLibrary\AdvancedNovaMediaLibraryServiceProvider]8;;\"
        this: Ebess\AdvancedNovaMediaLibrary\AdvancedNovaMediaLibraryServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/ebess/advanced-nova-media-library/src/AdvancedNovaMediaLibraryServiceProvider.php#L10\^]8;;\ {#117
          #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
        }
        file: "]8;;file:///Users/mbp/Projects/x/vendor/ebess/advanced-nova-media-library/src/AdvancedNovaMediaLibraryServiceProvider.php#L18\./vendor/ebess/advanced-nova-media-library/src/AdvancedNovaMediaLibraryServiceProvider.php]8;;\"
        line: "18 to 20"
      }
      2 => Closure()]8;;file:///Users/mbp/Projects/x/vendor/optimistdigital/nova-menu-builder/src/MenuBuilderServiceProvider.php#L27\^]8;;\ {#285
        class: "]8;;file:///Users/mbp/Projects/x/vendor/optimistdigital/nova-menu-builder/src/MenuBuilderServiceProvider.php#L12\OptimistDigital\MenuBuilder\MenuBuilderServiceProvider]8;;\"
        this: OptimistDigital\MenuBuilder\MenuBuilderServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/optimistdigital/nova-menu-builder/src/MenuBuilderServiceProvider.php#L12\^]8;;\ {#172
          #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
        }
        file: "]8;;file:///Users/mbp/Projects/x/vendor/optimistdigital/nova-menu-builder/src/MenuBuilderServiceProvider.php#L27\./vendor/optimistdigital/nova-menu-builder/src/MenuBuilderServiceProvider.php]8;;\"
        line: "27 to 29"
      }
      3 => Closure()]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php#L38\^]8;;\ {#324
        class: "]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php#L13\Illuminate\Foundation\Support\Providers\RouteServiceProvider]8;;\"
        this: App\Providers\RouteServiceProvider]8;;file:///Users/mbp/Projects/x/app/Providers/RouteServiceProvider.php#L8\^]8;;\ {#190
          #namespace: "App\Http\Controllers"
          #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
        }
        file: "]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php#L38\./vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php]8;;\"
        line: "38 to 41"
      }
    ]
    #terminatingCallbacks: []
    #serviceProviders: array:58 [
      0 => Illuminate\Events\EventServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Events/EventServiceProvider.php#L8\^]8;;\ {#459
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      1 => Illuminate\Log\LogServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Log/LogServiceProvider.php#L7\^]8;;\ {#7
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      2 => Illuminate\Routing\RoutingServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php#L17\^]8;;\ {#19
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      3 => Illuminate\Auth\AuthServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Auth/AuthServiceProvider.php#L13\^]8;;\ {#55
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      4 => Illuminate\Cookie\CookieServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Cookie/CookieServiceProvider.php#L7\^]8;;\ {#67
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      5 => Illuminate\Database\DatabaseServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php#L14\^]8;;\ {#69
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      6 => Illuminate\Encryption\EncryptionServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php#L10\^]8;;\ {#76
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      7 => Illuminate\Filesystem\FilesystemServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemServiceProvider.php#L7\^]8;;\ {#79
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      8 => Illuminate\Foundation\Providers\FormRequestServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php#L10\^]8;;\ {#85
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      9 => Illuminate\Foundation\Providers\FoundationServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FoundationServiceProvider.php#L10\^]8;;\ {#84
        #providers: array:1 [ …1]
        #instances: array:1 [ …1]
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      10 => Illuminate\Notifications\NotificationServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Notifications/NotificationServiceProvider.php#L9\^]8;;\ {#89
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      11 => Illuminate\Pagination\PaginationServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Pagination/PaginationServiceProvider.php#L7\^]8;;\ {#91
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      12 => Illuminate\Session\SessionServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Session/SessionServiceProvider.php#L9\^]8;;\ {#96
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      13 => Illuminate\View\ViewServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/View/ViewServiceProvider.php#L12\^]8;;\ {#100
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      14 => Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/barryvdh/laravel-ide-helper/src/IdeHelperServiceProvider.php#L23\^]8;;\ {#105
        #defer: true
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      15 => Benjaminhirsch\NovaSlugField\FieldServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/benjaminhirsch/nova-slug-field/src/FieldServiceProvider.php#L12\^]8;;\ {#116
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      16 => Ebess\AdvancedNovaMediaLibrary\AdvancedNovaMediaLibraryServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/ebess/advanced-nova-media-library/src/AdvancedNovaMediaLibraryServiceProvider.php#L10\^]8;;\ {#117}
      17 => Ebess\CollapsibleSidebar\AssetServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/ebess/nova-collapsible-sidebar/src/AssetServiceProvider.php#L9\^]8;;\ {#118
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      18 => Emilianotisato\NovaTinyMCE\FieldServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/emilianotisato/nova-tinymce/src/FieldServiceProvider.php#L10\^]8;;\ {#119
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      19 => Facade\Ignition\IgnitionServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/facade/ignition/src/IgnitionServiceProvider.php#L64\^]8;;\ {#120
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      20 => Fideloper\Proxy\TrustedProxyServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/fideloper/proxy/src/TrustedProxyServiceProvider.php#L9\^]8;;\ {#142
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      21 => Fruitcake\Cors\CorsServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/fruitcake/laravel-cors/src/CorsServiceProvider.php#L10\^]8;;\ {#141
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      22 => Intervention\Image\ImageServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/intervention/image/src/Intervention/Image/ImageServiceProvider.php#L9\^]8;;\ {#145
        #defer: false
        #provider: Intervention\Image\ImageServiceProviderLaravelRecent]8;;file:///Users/mbp/Projects/x/vendor/intervention/image/src/Intervention/Image/ImageServiceProviderLaravelRecent.php#L7\^]8;;\ {#146 …1}
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      23 => Laravel\Dusk\DuskServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/dusk/src/DuskServiceProvider.php#L8\^]8;;\ {#154
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      24 => Laravel\Nova\NovaCoreServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/nova/src/NovaCoreServiceProvider.php#L15\^]8;;\ {#156
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      25 => Laravel\Ui\UiServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/ui/src/UiServiceProvider.php#L8\^]8;;\ {#157
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      26 => Laravel\Vapor\VaporServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/laravel/vapor-core/src/VaporServiceProvider.php#L15\^]8;;\ {#159
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      27 => Carbon\Laravel\ServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/nesbot/carbon/src/Carbon/Laravel/ServiceProvider.php#L16\^]8;;\ {#169
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      28 => NunoMaduro\Collision\Adapters\Laravel\CollisionServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/nunomaduro/collision/src/Adapters/Laravel/CollisionServiceProvider.php#L30\^]8;;\ {#170
        #defer: true
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      29 => OptimistDigital\NovaLocaleField\FieldServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/optimistdigital/nova-locale-field/src/FieldServiceProvider.php#L9\^]8;;\ {#171
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      30 => OptimistDigital\MenuBuilder\MenuBuilderServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/optimistdigital/nova-menu-builder/src/MenuBuilderServiceProvider.php#L12\^]8;;\ {#172}
      31 => OptimistDigital\NovaSettings\ToolServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/optimistdigital/nova-settings/src/ToolServiceProvider.php#L11\^]8;;\ {#173
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      32 => Silvanite\NovaFieldCheckboxes\FieldServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/silvanite/novafieldcheckboxes/src/FieldServiceProvider.php#L9\^]8;;\ {#174
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      33 => Spatie\MediaLibrary\MediaLibraryServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/spatie/laravel-medialibrary/src/MediaLibraryServiceProvider.php#L15\^]8;;\ {#175
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      34 => Whitecube\NovaFlexibleContent\FieldServiceProvider]8;;file:///Users/mbp/Projects/x/vendor/whitecube/nova-flexible-content/src/FieldServiceProvider.php#L14\^]8;;\ {#184
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
      35 => App\Providers\AppServiceProvider]8;;file:///Users/mbp/Projects/x/app/Providers/AppServiceProvider.php#L7\^]8;;\ {#186
        #app: Illuminate\Foundation\Application]8;;file:///Users/mbp/Projects/x/vendor/laravel/framework/src/Illuminate/Foundation/Application.php#L29\^]8;;\ {#564}
      }
...
...
...

Complete log: https://pastebin.com/yQKzWpWR

NorthBlue333 commented 4 years ago

Running into this issue too! Putting the test on hold for now @martin-ro Have you found a solution ?

martin-ro commented 4 years ago

No, I was not able to solve this problem.

ahinkle commented 3 years ago

Hi there,

Here is my setup for combination between Laravel Blade components and this package - might be helpful.

class Page extends Model
{
    use HasFlexible;

    ...

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'content' => 'object',
    ];
}

Blade:

@if ($page->content)
    @foreach ($page->content as $content)
        @switch ($content->layout)
            @case ('html')
                <x:page-builder.html :component="$content" />
                @break
            @case ('wysiwyg')
                <x:page-builder.wysiwyg :component="$content" />
                @break
        @endswitch
    @endforeach
@endif

Content Add Test:

public function test_nova_page_can_add_content()
{
    $page = Page::factory()->make();

    $htmlLayout = [
        'layout'     => 'html',
        'key'        => 'key',
        'attributes' => [
            'html' => '<h1>Foo</h1>',
        ],
    ];

    $response = $this->post('/nova-api/pages/', array_merge(
        $page->getAttributes(),
        [
            'content' => [$htmlLayout],
        ],
    ));

    $response->assertCreated();
    $this->assertEquals(1, count($response->original['resource']['content']));
    $this->assertEquals($htmlLayout['layout'], $response->original['resource']['content'][0]->layout);
    $this->assertEquals($htmlLayout['attributes']['html'], $response->original['resource']['content'][0]->attributes->html);
}

Test Field Validation:

public function test_html_component_html_is_required()
{
    $page = Page::factory()->make();

    $htmlLayout = [
        'layout'     => 'html',
        'key'        => 'key',
        'attributes' => [
            'html' => null
        ],
    ];

    $response = $this->post('/nova-api/pages/', array_merge(
        $page->getAttributes(),
        [
            'content' => [$htmlLayout],
        ],
    ));

    $response->assertSessionHasErrors([
        'content.0.attributes.html' => 'The content.0.attributes.html field is required.',
    ]);
}

Test Appears on Page:

public function test_html_component_is_renderable_on_page()
{
    $page = Page::factory()->make();

    $htmlLayout = [
        'layout'     => 'html',
        'key'        => 'key',
        'attributes' => [
            'html' => '<h1>Foo</h1>',
        ],
    ];

    $response = $this->post('/nova-api/pages/', array_merge(
        $page->getAttributes(),
        [
            'content' => [$htmlLayout],
        ],
    ));

    $response->assertCreated();

    $response = $this->get($page->slug)->assertOk();

    $response->assertSee('<h1>Foo</h1>', false);
}