Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Module Route Middleware #763

Closed
lazosweb opened this issue May 15, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@lazosweb
Copy link

commented May 15, 2019

I have a project where I have a module with the name "Scanner" that has an Ajax route that will scan a page.

The Ajax route is like this.

Route::group([
'middleware' => 'permission:magazine.can.scan.page,book.can.scan.page',
'prefix' => 'scanner',
'as' => 'scanner.'], function () {   
 Route::get('scanPage', 'ScannerController@scanPage')->name('scanPage');
});

This "Scanner" Module is used by two other modules and let's say for example it's a "Magazines" Module and a "Books" Module.

Users that have access to the "Magazines" Module will have the permission to scan a page from a magazine and users that have access to the "Books" Module will have the permission to scan a page from a Book.

Both modules will call the same "Scanner" Module Ajax route above to scan a page. My code already knows whether the request came from the Magazine or the Book module but what I cannot figure out is how to dynamically add the permission middleware on the Ajax route without hard coding it on the Scan Module routes as on the example above.

If I later on add a new module for example "Newspaper" Module that will scan a page from a newspaper I will have to remember to add the "newspaper.can.scan.page" permission on the Ajax route.

Is there any way to achieve what I am asking?

@nWidart

This comment has been minimized.

Copy link
Owner

commented May 16, 2019

Hi,

I think you could achieve this by creating a custom middleware based on the permission middleware, but with your custom dynamic logic in it.

@lazosweb lazosweb closed this May 16, 2019

@lazosweb

This comment has been minimized.

Copy link
Author

commented May 16, 2019

Thanks. I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.