Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Feature | Models on Haystacks #45

Merged
merged 9 commits into from
Oct 1, 2022
Merged

Conversation

Sammyjo20
Copy link
Owner

@Sammyjo20 Sammyjo20 commented Oct 1, 2022

🚀 This PR introduces a handy helper method to define models that should be accessible to every job within the Haystack. Internally, it will serialize the model including its relationships and scopes and you will be able to retrieve the model in your code.

Haystack::build()
    ->addJob(new RecordPodcast)
    ->withModel($user)
    ->dispatch();

Inside your jobs...

$this->getHaystackModel(User::class);

This PR also introduces a beforeSave callback which is useful if you want to modify the Haystack model before it is created and dispatched.

Haystack::build()
    ->addJob(new RecordPodcast)
    ->beforeSave(function (Haystack $haystack) {
             $haystack->options->customOption = true;
     })
    ->dispatch();

This PR also introduces a new ability to set a custom option that you can use across your Haystack.

Haystack::build()
    ->addJob(new RecordPodcast)
    ->setOption('yeeHaw', '🤠')
    ->dispatch();

Inside your jobs...

$this->getHaystackOptions();

$this->getHaystackOption('yeeHaw');

Copy link
Owner Author

@Sammyjo20 Sammyjo20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review

@Sammyjo20 Sammyjo20 merged commit d9878d3 into main Oct 1, 2022
@Sammyjo20 Sammyjo20 deleted the feature/models-on-haystacks branch March 3, 2023 18:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant