Jrb
Jrb

Reputation: 461

View::composer not working on boot() service provider

Inside a Laravel Package EspacePartenaire I need to share some data between all its views using View Composer.

Ths boot() method inside EspacePartenaireServiceProvider containes the following:

$this->loadViewsFrom(__DIR__ . '/views', 'espace-partenaire');

View::composer('*', CurrentPartenaireComposer::class);

But I don't want to share data in all the views. I need it only in the views that are located in the view folder of the Package /packages/EspacePartenaire/src/views

When I change arguments of the composer function like below:

View::composer('espace-partenaire', CurrentPartenaireComposer::class);

or

View::composer('espace-partenaire::*', CurrentPartenaireComposer::class);

I had the error that my variables are undefined.

How can I achieve this?

EDIT: This is the Package routes file:

Route::group([
    'middleware' => ['web', 'auth'],
    'namespace' => 'App\Services\EspacePartenaire\Http\Controllers',
    'prefix' => 'espace-partenaire'
], function(){
    ...
    Route::get('/', 'EspacePartenaire@index');
    ...
});

Upvotes: 1

Views: 76

Answers (1)

mrhn
mrhn

Reputation: 18936

Based on your packages structure i think the following approach could maybe work, it seems first parameter is the path and you can do * as a wildcard.

View::composer('*espace-partenaire*', CurrentPartenaireComposer::class);

Upvotes: 1

Related Questions