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

Add generic type for WithData trait #597

Merged

Conversation

konovalexander
Copy link
Contributor

It becomes possible to add PHPDoc when using the "WithData" trait:

class CommentRequest extends FormRequest {

    /** @use WithData<\App\Data\CommentData> */
    use WithData;

    protected string $dataClass = CommentData::class;

    //Some code
}

Then type hinting works correctly after calling the "getData" method:

public function store(CommentRequest $request): JsonResponse {
    
    $commentData = $request->getData();
    //$commentData is now of type CommentData
    
    //Some code
}

@rubenvanassche
Copy link
Member

Fancy 😍 , thanks!

@rubenvanassche rubenvanassche merged commit 02752fc into spatie:main Dec 1, 2023
1 check passed
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.

2 participants