Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jaspermutsaerts-paqt
Copy link

@jaspermutsaerts-paqt jaspermutsaerts-paqt commented Aug 28, 2025

Within our own projects we missed the ability to leverage WithoutRelations for queueable actions.

Laravel's Illuminate\Queue\Attributes\WithoutRelations can not be used to offer the same functionality, because it does not support parameters, only classes and properties.

This PR introduces support for \Spatie\QueueableAction\Attributes\WithoutRelations which should have the same behavior.

I did not find specific cons, nor requests, for this feature. So I'm not sure how many people need it, but I liked it, so decided to share.

Usage can be on parameter level:

use Spatie\QueueableAction;
use Spatie\QueueableAction\Attributes\WithoutRelations;

class MyInvokeableAction
{
    use QueueableAction;

    public function __invoke(
        #[WithoutRelations] MyModel $model,
        MyModel $otherModel,
        RequestData $requestData
    ) {
        // $model does not contain its relations until loaded explicitly
        // $otherModel is unaffected and may contain loaded relations
        // $requestData is unaffected
    }
}

or on class level:

use Spatie\QueueableAction;
use Spatie\QueueableAction\Attributes\WithoutRelations;

#[WithoutRelations] 
class MyInvokeableAction
{
    use QueueableAction;

    public function __invoke(
        MyModel $model,
        MyModel $otherModel,
        RequestData $requestData
    ) {
        // $model does not contain its relations until loaded explicitly
        // $otherModel also does not contain its relations until loaded explicitly
        // $requestData is unaffected
    }
}

it will also work for models in arrays or collections.

It would have been possible to also support Laravel's Illuminate\Queue\Attributes\WithoutRelations on class level, but since that is not currently a dependency of this project and perhaps it's clearer if we only support one, for consistency.

@jaspermutsaerts-paqt jaspermutsaerts-paqt force-pushed the support-without-relations-as-parameter branch from b43f4ac to b2bd9d7 Compare August 28, 2025 11:56
@jaspermutsaerts-paqt jaspermutsaerts-paqt force-pushed the support-without-relations-as-parameter branch from 23a9cc8 to 7660ece Compare August 28, 2025 12:07
@jaspermutsaerts-paqt
Copy link
Author

Note: I was wondering about code style,

wether the methods resolveParameters & resolveWithoutRelationsParameter should be moved to a trait (and resolveParameters renamed accordingly) since it does increase the line length of ActionJob significantly

@jaspermutsaerts-paqt jaspermutsaerts-paqt marked this pull request as ready for review August 28, 2025 12:37
@jaspermutsaerts-paqt jaspermutsaerts-paqt changed the title Support WithoutRelations for QueuableAction parameters to emulate Laravel's WithoutRelations attribute for job properties. Support WithoutRelations for QueuableAction parameters to emulate Laravel's WithoutRelations attribute Aug 28, 2025
@jaspermutsaerts-paqt jaspermutsaerts-paqt changed the title Support WithoutRelations for QueuableAction parameters to emulate Laravel's WithoutRelations attribute Support WithoutRelations for QueuableAction class & parameters to emulate Laravel's WithoutRelations attribute Aug 28, 2025
@jaspermutsaerts-paqt jaspermutsaerts-paqt changed the title Support WithoutRelations for QueuableAction class & parameters to emulate Laravel's WithoutRelations attribute Support WithoutRelations for queueable action class & parameters to emulate Laravel's WithoutRelations attribute Aug 28, 2025
@jaspermutsaerts-paqt jaspermutsaerts-paqt force-pushed the support-without-relations-as-parameter branch from 23b630e to e533cf7 Compare August 28, 2025 16:51
@jaspermutsaerts-paqt
Copy link
Author

I did not find specific cons, nor requests, for this feature. So I'm not sure how many people need it, but I liked it, so decided to share.

I now did find it: #65

We're not adding any new features to this package.

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