Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.17k stars 896 forks source link

ViewComposer not working with Dashboard template per documentation. #2318

Closed selected-pixel-jameson closed 4 years ago

selected-pixel-jameson commented 4 years ago

I'm attempting to register a View Composer for the Laravel Backpack libraries dashboard template, which is located at resources/views/vendor/backpack/base/dashboard.blade.php within my project.

I'm doing so via

View::composer(
   'vendor.backpack.base.dashboard', 'App\Http\View\Composers\DashboardComposer'
);

I know that the Composer is working correctly, because if I change the template to

View::composer(
   '*', 'App\Http\View\Composers\DashboardComposer'
);

the dashboard page loads correctly with the variable I'm setting in the composer.

I've tested to see if the view reference is correct by using

if (View::exists('vendor.backpack.base.dashboard')) {
    //
}

which returns successfully.

I'm registering my provider, App\Providers\ViewServiceProvider::class, within the config as the very last provider.

PHP 7.4.0 (cli) (built: Nov 28 2019 07:27:06) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies

LARAVEL VERSION:

laravel/framework v5.8.35 The Laravel Framework.

BACKPACK VERSION:

backpack/crud 4.0.23 Quickly build an admin interfaces using Laravel 6, CoreUI, Boostrap 4 and jQuery. backpack/generators 2.0.5 Generate files for laravel projects

pxpm commented 4 years ago

Hello @selected-pixel-jameson

I think this is not related to backpack, you should have a look at views from packages in laravel. overriding package views

To correct your problem you should use the view path as follow: (not necessarily use it as callback if you have some file that is the view composer):

View::composer('backpack::dashboard', function ($view) {
            return $view->with('test','test');
        });

For future reference this kind of questions should be asked in other channels like gitter or stackoverflow. We keep github for bugs/features.

Best, Pedro

support[bot] commented 4 years ago

Oups!

Looks like this is a support request, not a bug/feature. Could you please repost on StackOverflow, using the backpack-for-laravel tag?

Background: Here at Backpack we use Github Issues only for tracking bugs and features, not individual implementation issues. This helps a lot in keeping our focus on improving Backpack. Thanks a lot for understanding!

Here are all the Backpack communication mediums:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or StackOverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

PS. In case I mistakenly closed your issue, yell :-) I'm a robot, I make mistakes.