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

Use container to call Data::authorize() to allow for dependencies #910

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cosmastech
Copy link

@cosmastech cosmastech commented Dec 5, 2024

I want to build a request object that leverages Laravel's new contextual attributes. For instance:

class CreatePodcast extends Data
{
    public function __construct(
        public string $name,
        public bool $premium
    ) {
    }

    public static function authorize(
        #[CurrentUser] User $user,
        #[RouteParameter('org')] Organization $org
    ): bool
    {
        return $user->can('createPodcastFor', $org);
    }
}

While it's possible to add a custom DataPipe to pipelines(), this seems like it would be a pretty common use-case for folks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant