Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Brotzka's avatar

Include a view from a package

Hey,

is there a possibility to include a view from a package? I have a controller which returns a view from resources/views, so nothing special. But from this view, I want to include a view from a package I am developing. I tried the following, but with no success.

@include('vendor.brotzka-databaselogger.list')
{{ view('brotzka-databaselogger::list') }}

It works from the Controller (in app/Http/Controllers) with:

return view('brotzka-databaselogger::list');

Any idea, how to load a package view from within a normal view?

0 likes
6 replies
Brotzka's avatar

No, that doesn't work, too. Also no output.

zachleigh's avatar

This works perfectly for me. Ive tried it in two apps with no problems at all.

@include('brotzka-databaselogger::list', ['variable1' => [1,2,3], 'variable2' => 'test'])

Does the package load views in its service provider?

$this->loadViewsFrom(__DIR__.'/path/to/views', 'viewName');
Brotzka's avatar

Yes, it does. This is my ServiceProvider:

namespace Fabs87\Databaselogger;

use Illuminate\Support\ServiceProvider;

class DatabaseloggerServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind('brotzka-databaselogger', function() {
            return new Databaselogger;
        });

        $this->mergeConfigFrom(__DIR__ . '/config/databaselogger.php', 'brotzka-databaselogger');
    }

    public function boot(){

        $this->loadViewsFrom(__DIR__ . '/views', 'brotzka-databaselogger');
        $this->publishes(
            [__DIR__ . '/views' => base_path('resources/views/vendor/brotzka-databaselogger')],
            'views'
        );

        $this->publishes(
            // Keep the config_path() empty, so the config file will be published directly to the config directory
            [__DIR__ . '/config' => config_path()],
            'config'
        );

        $this->publishes([
            __DIR__ . '/migrations' => $this->app->databasePath() . '/migrations'
        ], 'migrations');
    }
}
zachleigh's avatar

Maybe the problem is that you're publishing views and also trying to load them from the vendor package? What happens if you comment out this line: $this->publishes( [__DIR__ . '/views' => base_path('resources/views/vendor/brotzka-databaselogger')], 'views' );

Brotzka's avatar
Brotzka
OP
Best Answer
Level 1

I found the problem.. I had a typo in my layout view. Instead of @yield('content') I had @section('content'). Now everything works.

Thanks for your time @zachleigh :)

Please or to participate in this conversation.