kenepa / resource-lock

Filament Resource Lock is a Filament plugin that adds resource locking functionality to your site.
MIT License
81 stars 18 forks source link

Feature Request: Allow Passing Additional Arguments to Gate Definitions and Checks #51

Open MB116 opened 4 months ago

MB116 commented 4 months ago

Description:

Currently, when defining a gate using Gate::define with a policy and method, there's no direct way to pass additional arguments beyond the authenticated user. This limitation makes it difficult to use policies for authorization scenarios that require context beyond the user, such as checking permissions on a specific model instance.

Suggested Solution:

I propose adding the ability to pass additional arguments when defining gates and when performing authorization checks. This could be achieved in a few ways:

Variadic Arguments:

Modify Gate::define to accept a variable number of arguments after the policy and method. Modify Gate::allows to accept the same variable number of arguments after the gate name. Internally, pass these additional arguments to the policy method when it's called.

Array of Arguments:

Allow passing an array as the second argument to Gate::define, where the first element is the policy/method and the rest are additional arguments. Allow passing the same array structure to Gate::allows.

asmossunov commented 4 months ago

+1