Hi There,
Is is already possible, or do you have plans to allow for policies and exceptions to be within the modules created by laravel-modules?
For policies, it looks like it is possible with the registerPolicies function within the AuthServiceProvider. So would each module require an instance of the AuthServiceProvider to register their policies? Or would it be easier to register each module's policies within the global AuthServiceProvider?
I assume that exception classes will be auto loaded by default, so it is just a case of creating a folder within each module and place the exceptions in there?
Thanks in advance for any advice offered.
Hello,
You can already define you policies inside a module.
For that you need to create a service provider in your module, that extends Illuminate\Foundation\Support\Providers\AuthServiceProvider. In there you can do anything the documentation says.
You could also register the policies in the AuthServiceProvider under the app namespace.
And yes exceptions are just as any other class, meaning they get autoloaded by composer.
Thanks again for the advice
Hi, i reopened the issue for going further with an aspect.
How i can add the policies of the module to the global application?
I've a partial view in the project where I need to check if i can create/view/other on a certain class of object.
I was able to do this adding the policies inside the global AuthServiceProvider, but i would like to make it work without editing the main provider.
I declared an AuthServiceProvider inside a module but the policies inside it, seem to not be loaded/used.
Can you give me some help?
Thanks in advance,
Simone
I solved.
You have to add $this->app->register(AuthServiceProvider::class); inside _register_ function of the NAMEMODULEServiceProvider.php
Most helpful comment
Hello,
You can already define you policies inside a module.
For that you need to create a service provider in your module, that extends
Illuminate\Foundation\Support\Providers\AuthServiceProvider. In there you can do anything the documentation says.You could also register the policies in the
AuthServiceProviderunder the app namespace.And yes exceptions are just as any other class, meaning they get autoloaded by composer.