Download the PHP package hatchyu/laravel-eloquent-foundation without Composer
On this page you can find all versions of the php package hatchyu/laravel-eloquent-foundation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hatchyu/laravel-eloquent-foundation
More information about hatchyu/laravel-eloquent-foundation
Files in hatchyu/laravel-eloquent-foundation
Package laravel-eloquent-foundation
Short Description Foundational Eloquent traits and scopes for Laravel applications
License MIT
Informations about the package laravel-eloquent-foundation
Hatchyu Laravel Eloquent Foundation
Foundational Eloquent traits and scopes for strict, opinionated Laravel applications.
This package provides a set of reusable traits for common Eloquent patterns such as UUID keys, audit fields (creator/updater), media uploading, and ownership scoping.
[!WARNING] This package is currently under active development and is primarily being used in my personal Laravel projects. Expect changes and improvements as it continues to evolve.
Installation
Optionally, publish the configuration (if available in future updates):
Usage
1. Primary Keys (UUID / ULID)
Easily switch your models to use UUIDs or ULIDs as primary keys.
UUID:
ULID:
2. Audit Trails (Creator, Updater, Deleter)
Automatically track who created, updated, or deleted a record. These traits assume you have standard created_by, updated_by, and deleted_by columns in your database.
3. Media Uploading
The HasMediaUploader trait simplifies handling file uploads directly in your Eloquent models. It automatically detects UploadedFile instances assigned to attributes, uploads them to storage, and saves the path.
Features:
- Automatic storage to
publicdisk. - Deletes the old file when replaced.
- Safe for usage within transactions (uploads effectively happen
afterCommit).
4. Image URL Accessors
The HasImageUrls trait provides dynamic accessors for your image paths, useful for APIs.
Result:
If you have an avatar column, you automatically get:
$user->avatar_url(Original URL)$user->avatar_thumb_url(Thumbnail URL)
You can customize the dimensions by overriding imageDimensions() in your model.
5. Ownership & Row Scoping
The HasOwner and BelongsToOwnerTenant traits provide automatic assignment and global query scoping based on the authenticated user.
Functionality:
- Global Scope (
OwnerScope): Automatically scopes queries toowner_id = Auth::id(). - Auto-Assignment: Automatically sets
owner_id = Auth::id()when creating models. - Escape Macro: Allows bypassing the owner scope when needed using
Post::withoutOwner()->get(). - Customizable Column: Configured via
config('eloquent-foundation.columns.owner')(defaults toowner_id).
Helpers
The package includes global helper functions:
eloquent_ulid(): Generate a valid ULID string.avatar_url($path, $width, $height): Generate a URL for an image path (supports resizing placeholders).
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-eloquent-foundation with dependencies
illuminate/database Version ^11.0||^12.0||^13.0
illuminate/auth Version ^11.0||^12.0||^13.0
illuminate/support Version ^11.0||^12.0||^13.0