How do I inject a view into a backend admin slot?

Any view you wish to inject into a slot should be defined in a Service Provider.

If the code is unique to a particular store it could be placed in the boot method of the AppServiceProvider. If it is to be included as part of a module, then it can be added in the setup method of the module's ServiceProvider.

When registering the view to be injected into the slot, you must provide the slot name along with the view, for example:


namespace Acme\MyModule;

use Aero\Admin\AdminSlot;
use Aero\Common\Providers\ModuleServiceProvider;

class ServiceProvider extends ModuleServiceProvider
    public function setup(): void 
        AdminSlot::inject('', 'my-module::admin-slot');

For advanced cases where additional data needs to be passed into your view, a closure can be used. The closure receives a $data parameter that contains the current variables on the page.

AdminSlot::inject('', function ($data) {
    // add custom variables to the $data array

    return view('my-module::admin-slot', $data);

Articles in this section

Was this article helpful?
0 out of 0 found this helpful