open-southeners/extended-laravel
Adds handy Laravel extensions and helper utilities to streamline common tasks and reduce boilerplate. Designed as a lightweight add-on for projects needing extra convenience features beyond the core framework, with simple installation and integration.
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.
Gets model fully qualified class or instanced object from given string.
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'
Checks if object or class is a Eloquent model.
Helpers::isModel(App\Models\Post::class);
// true
Helpers::isModel(new App\Models\Post());
// true
Creates a model instance from given key (generally its ID or specified primary key).
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
Tries to get Eloquent model key from given variable (can be of multiple types).
Helpers::keyFrom('1');
// 1
Helpers::keyFrom('80b6dc25-8773-4639-abcf-ed1f157deea1');
// '80b6dc25-8773-4639-abcf-ed1f157deea1'
Helpers::keyFrom(App\Models\Post::find(1));
// 1
Gets always a new Eloquent query builder instance from given model.
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
Get cache atomic locks owner or false otherwise if no lock found.
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']
How can I help you explore Laravel packages today?