Comments (7)
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.
from laravel-modules.
I solved.
You have to add $this->app->register(AuthServiceProvider::class);
inside register function of the NAMEMODULEServiceProvider.php
from laravel-modules.
Thanks again for the advice
from laravel-modules.
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
from laravel-modules.
The same problem, can't solve
from laravel-modules.
I have the same problem.
My MODULENAMEServiceProvider has
public function register()
{
$this->app->register(RouteServiceProvider::class);
$this->app->register(TemplateAuthServiceProvider::class);
}
In TemplateAuthServiceProvider I have
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class TemplateAuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'Modules\Template\Entities\Template' => 'Modules\Template\Policies\TemplatePolicy',
'Modules\Template\Entities\TemplateTab' => 'Modules\Template\Policies\TemplatePolicy',
];
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
}
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot()
{
$this->registerPolicies();
}
My controller which is inside the module has
public function index(Request $request)
{
//checks policy
$this->authorize('list', Template::class);
The policy contains
public function list(Admin $admin)
{
dd(567);
}
what could be the reason for the system not to trigger the policy function?
from laravel-modules.
I have the same problem.
My MODULENAMEServiceProvider has
public function register() { $this->app->register(RouteServiceProvider::class); $this->app->register(TemplateAuthServiceProvider::class); }
In TemplateAuthServiceProvider I have
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class TemplateAuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * * @var array */ protected $policies = [ 'Modules\Template\Entities\Template' => 'Modules\Template\Policies\TemplatePolicy', 'Modules\Template\Entities\TemplateTab' => 'Modules\Template\Policies\TemplatePolicy', ]; /** * Register the service provider. * * @return void */ public function register() { } /** * Register any application authentication / authorization services. * * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return void */ public function boot() { $this->registerPolicies(); }
My controller which is inside the module has
public function index(Request $request) { //checks policy $this->authorize('list', Template::class);
The policy contains
public function list(Admin $admin) { dd(567); }
what could be the reason for the system not to trigger the policy function?
I have the same problem
from laravel-modules.
Related Issues (20)
- Class "Modules\Hello\Providers\HelloServiceProvider" not found HOT 3
- Need to add two command "make:enum" and "make:class" for the modules HOT 2
- Target a specific part of standard page of Laravel project by modules HOT 3
- database seeder issue HOT 3
- Class Module ServiceProvider not found in laravel 11 HOT 1
- Migration Command Not Working HOT 4
- How To Work With Subscriber? HOT 1
- Composer task HOT 2
- Behavior Config HOT 1
- File does not exist at path HOT 2
- Modular inertiajs HOT 3
- Docs causing infinite redirects HOT 2
- Migration Invalid Priority HOT 2
- Issue with Namespace in laravel-modules and laravel-modules-livewire Packages - Unable to find component: [blog::index] HOT 1
- TypeError in Builder.php when using call_user_func_array() HOT 1
- Custom modules.paths.app_folder value not working HOT 1
- Extending Laravel 11 EventServiceProvider HOT 1
- Why doesn't SeedCommand have a direction option? HOT 2
- Laravel 11 The route setting in the module is not effective HOT 1
- Target class [cache] does not exist when using Redis as a session driver HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-modules.