PHP code example of hatchyu / laravel-eloquent-foundation

1. Go to this page and download the library: Download hatchyu/laravel-eloquent-foundation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hatchyu / laravel-eloquent-foundation example snippets


use Hatchyu\Eloquent\Foundation\Concerns\UuidPrimary;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    use UuidPrimary;
}

use Hatchyu\Eloquent\Foundation\Concerns\UlidPrimary;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use UlidPrimary;
}

use Hatchyu\Eloquent\Foundation\Concerns\HasCreator;
use Hatchyu\Eloquent\Foundation\Concerns\HasUpdater;
use Hatchyu\Eloquent\Foundation\Concerns\HasDeleter;

class Post extends Model
{
    use HasCreator, HasUpdater, HasDeleter;
    
    // Automatically sets 'created_by' to Auth::id() on creation
    // Automatically sets 'updated_by' to Auth::id() on update
    // Automatically sets 'deleted_by' to Auth::id() on soft deletion
}

use Hatchyu\Eloquent\Foundation\Concerns\HasMediaUploader;

class User extends Model
{
    use HasMediaUploader;

    // Optional: Define upload path (defaults to 'uploads/default')
    const FILE_UPLOAD_PATH = 'uploads/avatars';
}

// Usage in Controller
$user->avatar = $request->file('avatar'); 
$user->save(); // File is uploaded, path is saved to DB

use Hatchyu\Eloquent\Foundation\Concerns\HasImageUrls;

class User extends Model
{
    use HasImageUrls;

    protected array $imageFields = ['avatar'];
}

use Hatchyu\Eloquent\Foundation\Concerns\BelongsToOwnerTenant;

class Post extends Model
{
    use BelongsToOwnerTenant;
}
bash
php artisan vendor:publish --tag=eloquent-foundation-config