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.
Global functions like uuidV4(), slug(), arrayGet(), and fileUpload() are available everywhere in the framework.
The db() and table() helpers expose Eloquent directly. Always query in controllers and pass clean arrays to views.
Twig auto-escapes all output by default. Use {{ value|raw }} only when the source is explicitly trusted.
String & ID Helpers
Live OutputuuidV4()
Unique ID GeneratorGenerates a cryptographically random RFC 4122 UUID v4. No database round-trip required.
012c156e-35c1-4bd0-a9a5-53068519d7b7
$uuid = uuidV4();
// → "012c156e-35c1-4bd0-a9a5-53068519d7b7"
slug()
URL NormalizerConverts any string into a lowercase, hyphenated, URL-safe slug. Handles special characters and extra spaces.
"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 ConnectedConfigure 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,
]);
}