PHP code example of lioneagle / le-utils

1. Go to this page and download the library: Download lioneagle/le-utils 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/ */

    

lioneagle / le-utils example snippets




namespace Lioneagle\LeUtils\Tests\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Lioneagle\LeUtils\Contracts\Uuidable;
use Lioneagle\LeUtils\Traits\HasUuid;

class User extends Model implements Uuidable
{
    use HasUuid;

    protected $fillable = ['name'];

    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }
}

$uuid = '942e28b5-63e3-4475-8d96-4f04ab0f627f';

$user = User::uuid($uuid);
$user = User::query()->uuid($uuid);

$post = User::posts()->uuid($uuid);



namespace Lioneagle\LeUtils\Query;

use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Lioneagle\LeUtils\Contracts\UuidBuilderInterface;
use Lioneagle\LeUtils\Traits\BuilderUuidScope;

class CustomBuilder extends EloquentBuilder implements UuidBuilderInterface
{
    use BuilderUuidScope;

    public function whereActive()
    {
        return $this->where('active', 1);
    }
}

class User extends Model implements Uuidable
{
    use HasUuid;

    protected $fillable = ['name'];

    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }

    public function newEloquentBuilder($query): UuidBuilderInterface
    {
        return new CustomBuilder($query);
    }
}