How to get access to route params from validation? #286
Unanswered
bradleybernard
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Hi @bradleybernard :) if I understand correctlly, the soo you can do the same thing with the use Illuminate\Http\Request;
class SongData extends Data
{
public function __construct(
public string $title,
public string $artist,
) {
}
public function authorize(): bool
{
return Auth::user()->can(
'delete',
Request::route('myModel')
);
}
} If I am wrong please tell me https://spatie.be/docs/laravel-data/v2/as-a-data-transfer-object/request-to-data-object |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Usually in my form requests I'll run a model policy by:
How can I do that with the static method authorize available? I dug into src and it looks like authorize is called with no params, so I wasn't able to access the Request $request object, since it doesn't resolve from container.
Any advice here? Right now I'd have to have a form request + laravel-data model file, which is a lot.
I know laravel-data is supposed to be more "abstract" but having a form where you use laravel-data to edit the model, it makes sense to have a form request like way to validate authorization to that model. Curious if I missed something in the docs or someone has a solution for this!
Any help would be appreciated. Thank you! :)
Beta Was this translation helpful? Give feedback.
All reactions