⬡ Lacelium
⌘K
Version 2.x ▾
Live Demo

Helpers & Database

A hands-on demonstration of Lacelium's global helper functions and the Eloquent-powered database layer — running live from the controller right now.

Utility Helpers

Global functions like uuidV4(), slug(), arrayGet(), and fileUpload() are available everywhere in the framework.

Database Layer

The db() and table() helpers expose Eloquent directly. Always query in controllers and pass clean arrays to views.

Safe Escaping

Twig auto-escapes all output by default. Use {{ value|raw }} only when the source is explicitly trusted.

String & ID Helpers

Live Output

uuidV4()

Unique ID Generator

Generates a cryptographically random RFC 4122 UUID v4. No database round-trip required.

Generated this request: 6e9b11ac-3732-4aed-8336-4e67989b92e8
$uuid = uuidV4();
// → "6e9b11ac-3732-4aed-8336-4e67989b92e8"

slug()

URL Normalizer

Converts any string into a lowercase, hyphenated, URL-safe slug. Handles special characters and extra spaces.

Input → Output:
"Hello Helpers Demo" → hello-helpers-demo
$slug = slug('Hello Helpers Demo');
// → "hello-helpers-demo"

Other Available Helpers

arrayGet($arr, 'a.b.c')

Safely retrieve nested array values using dot notation with an optional default.

fileUpload($file, 'storage/uploads')

Handle uploaded file persistence with auto-naming and directory validation.

env('APP_NAME', 'default')

Read environment variables with type casting for true, false, null.

Database Layer

● Not Connected
Connection failed: Class "Lacelium\Core\Database\DatabaseManager" not found

Configure your database in .env or config/database.php and ensure the server is reachable.

# .env
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_app
DB_USERNAME=root
DB_PASSWORD=secret

Recommended Controller Pattern

Always query data in your controller and pass clean PHP arrays or collections to Twig. Avoid calling table() directly inside templates.

// app/Http/Controllers/ExampleController.php

public function helpersPage(Request $request): Response
{
    $uuid = uuidV4();
    $slug = slug('Hello Helpers Demo');

    $conn        = db();
    $taskCount   = table('tasks')->count();
    $recentTasks = table('tasks')->orderBy('id', 'desc')->limit(5)->get()->all();

    return $this->render('docs/examples/helpers.twig', [
        'uuid'           => $uuid,
        'slug'           => $slug,
        'dbOk'           => true,
        'connectionName' => $conn->getName(),
        'taskCount'      => $taskCount,
        'recentTasks'    => $recentTasks,
    ]);
}