> For the complete documentation index, see [llms.txt](https://docs.opensoutheners.com/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opensoutheners.com/home/extended-laravel/function-helpers.md).

# Helpers

List of functions that works for Laravel Eloquent models.

This is the list of functions that you can import and use on your Laravel app through the static methods of the `OpenSoutheners\ExtendedLaravel\Helpers` class.

## modelFrom

Gets model fully qualified class or instanced object from given string.

```php
Helpers::modelFrom('post');
// 'App\Models\Post'

Helpers::modelFrom('post', false);
// object instance for App\Models\Post

Helpers::modelFrom('post', true, 'Domain\Posts');
// 'Domain\Posts\Post'
```

## isModel

Checks if object or class is a Eloquent model.

```php
Helpers::isModel(App\Models\Post::class);
// true

Helpers::isModel(new App\Models\Post());
// true
```

## instanceFrom

Creates a model instance from given key (generally its ID or specified primary key).

```php
Helpers::instanceFrom(1, App\Models\Post::class);
// object instance for App\Models\Post with ID 1

Helpers::instanceFrom(1, App\Models\Post::class, ['id', 'title']);
// object instance for App\Models\Post with ID 1 and only selecting id and title columns

Helpers::instanceFrom(1, App\Models\Post::class, ['*'], ['author']);
// object instance for App\Models\Post with ID 1 and with author relationship loaded
```

## keyFrom

Tries to get Eloquent model key from given variable (can be of multiple types).

```php
Helpers::keyFrom('1');
// 1

Helpers::keyFrom('80b6dc25-8773-4639-abcf-ed1f157deea1');
// '80b6dc25-8773-4639-abcf-ed1f157deea1'

Helpers::keyFrom(App\Models\Post::find(1));
// 1
```

## queryFrom

Gets always a new Eloquent query builder instance from given model.

```php
Helpers::queryFrom(App\Models\Post::class);
// object instance for \Illuminate\Database\Eloquent\Builder

Helpers::queryFrom(App\Models\Post::query()->where('title', 'hello'));
// new object instance for \Illuminate\Database\Eloquent\Builder
```

## getCacheLockOwner

Get cache atomic locks owner or false otherwise if no lock found.

```php
Cache::lock('podcasts.1.upload')->get();

Helpers::getCacheLockOwner('podcasts.1.upload');
// 432afra2pjna

Cache::lock('podcasts.2.upload')->get();

Helpers::getCacheLockOwner('podcasts.*');
// ['podcasts.1.upload', 'podcasts.2.upload']
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.opensoutheners.com/home/extended-laravel/function-helpers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
