# Shared Models

You can also provide models when creating Haystacks which will be accessible to every job. This is extremely useful as you don't have to pass the model into every job. Just use the `withModel` method when building your Haystack to store a model.&#x20;

<pre class="language-php"><code class="lang-php">&#x3C;?php

$user = Auth::user();

Haystack::build()
    ->addJob(new RecordPodcast)
<strong>    ->withModel($user)
</strong>    ->dispatch();
</code></pre>

You can also provide an optional `$key` as the second argument.&#x20;

<pre class="language-php"><code class="lang-php">&#x3C;?php

$user = Auth::user();

Haystack::build()
    ->addJob(new RecordPodcast)
<strong>    ->withModel($user, 'admin')
</strong>    ->dispatch();
</code></pre>

Then, inside your jobs you can call the `getHaystackModel` method. If you did not provide a key, you can just pass in the model's class name.

```php
$user = $this->getHaystackModel(User::class);

// Or if you specified a key...

$this->getHaystackModel('admin');
```

{% hint style="info" %}
Laravel Haystack will serialize your models including their loaded relationships. It will only retrieve the model and the relationships when you attempt to get the model.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.laravel-haystack.dev/cool-features/shared-models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
