Skip to content

Helpers

Laureano F. Lamonega edited this page Jul 17, 2026 · 1 revision

Helpers

Global helper functions available anywhere in your application.

view(string $path, array $data = [], ?string $layout = null): Response

Render a view and return a Response with text/html content type.

return view('users/index', ['users' => $users]);
return view('users/index', $data, 'layouts/main');

redirect(string $url, int $status = 302): Response

Create a redirect response.

return redirect('/login');
return redirect('/dashboard', 301);

e(?string $value): string

Escape HTML to prevent XSS.

echo e($userInput);
echo e($user->name);  // Used in native PHP views

env(string $key, mixed $default = null): mixed

Get an environment variable with type-casting support.

$debug = env('APP_DEBUG', false);   // bool
$name  = env('DB_NAME', 'myapp');   // string
$host  = env('DB_HOST');            // null if not set

Values are type-cast: 'true'/'yes'/'1'true, 'false'/'no'/'0'false, 'null'/''null.

route(string $name, array $params = []): string

Generate a URL from a named route.

route('posts.show', ['slug' => 'hello-world']);  // /posts/hello-world

Throws RuntimeException if the route name is not defined.

config(string $key, mixed $default = null): mixed

Get a config value using dot notation.

$timezone = config('app.timezone', 'UTC');
$dbHost   = config('database.connections.mysql.host');

dd(mixed ...$vars): never

Dump variables and die. Outputs formatted var_dump() with syntax highlighting.

dd($user, $request->all());

ddj(mixed ...$vars): never

Dump variables as JSON and die.

ddj($user);               // Single variable
ddj($users, $request);    // Multiple variables as array

Clone this wiki locally