API Documentation
Table of Contents
Namespaces
Classes
- Constants
- Class Constants
Functions
- auth() : Authenticatable|null
- isGuest() : bool
- db() : DatabaseDriver
- Retrieves the database driver instance from the application kernel.
- hashString() : string
- json() : Response
- Returns a JSON response with the given data.
- redirect() : Response
- Redirects the user to the specified URI.
- view() : Response
- Renders a view and returns it as a HTTP response.
- request() : Request
- Retrieves the current HTTP request instance.
- back() : Response
- Redirects the user to the previous request URL stored in the session.
- app() : mixed
- Retrieve an instance of the specified class from the container.
- singleton() : mixed
- Registers or retrieves a singleton instance of a class in the container.
- env() : mixed
- Retrieves the value of an environment variable.
- resourcesDirectory() : string
- Retrieves the path to the resources directory.
- config() : mixed
- Retrieve a configuration value by its key.
- session() : Session
- Retrieve the current session instance.
- error() : string|null
- Retrieves the first error message for a specific field from the session.
- old() : mixed|null
- Retrieve old input data for a given field from the session.
- snake_case() : string
- Converts a given string to snake_case.
Functions
auth()
auth() : Authenticatable|null
Return values
Authenticatable|nullisGuest()
isGuest() : bool
Return values
booldb()
Retrieves the database driver instance from the application kernel.
db() : DatabaseDriver
Tags
Return values
DatabaseDriver —The database driver instance.
hashString()
hashString(string $data) : string
Parameters
- $data : string
Return values
stringjson()
Returns a JSON response with the given data.
json(array<string|int, mixed> $data) : Response
Parameters
- $data : array<string|int, mixed>
-
The data to be encoded as JSON and returned in the response.
Return values
Response —The JSON response object.
redirect()
Redirects the user to the specified URI.
redirect(string $uri) : Response
This function generates a redirect response to the given URI.
Parameters
- $uri : string
-
The URI to redirect to.
Return values
Response —The redirect response object.
view()
Renders a view and returns it as a HTTP response.
view(string $view[, array<string|int, mixed> $data = [] ][, string|null $layout = null ]) : Response
Parameters
- $view : string
-
The name of the view file to render.
- $data : array<string|int, mixed> = []
-
An associative array of data to pass to the view.
- $layout : string|null = null
-
Optional layout to wrap the view content.
Return values
Response —The HTTP response containing the rendered view.
request()
Retrieves the current HTTP request instance.
request() : Request
This function fetches the current request object from the application kernel.
If the application instance is not of type Kernel
, an exception is thrown.
Tags
Return values
Request —The current HTTP request instance.
back()
Redirects the user to the previous request URL stored in the session.
back() : Response
If no previous URL is found, it defaults to the root ("/").
Return values
Response —The HTTP response object for the redirection.
app()
Retrieve an instance of the specified class from the container.
app([string $class = Kernel::class ]) : mixed
By default, this function resolves the Kernel
class, but you can specify
a different class to resolve by passing its fully qualified class name.
Parameters
- $class : string = Kernel::class
-
The fully qualified class name to resolve. Defaults to
Kernel::class
.
Return values
mixed —The resolved instance of the specified class.
singleton()
Registers or retrieves a singleton instance of a class in the container.
singleton(string $class[, string|callable|null $build = null ]) : mixed
This function ensures that only one instance of the specified class is created and shared throughout the application. If a callable or a specific build logic is provided, it will be used to construct the instance.
Parameters
- $class : string
-
The fully qualified class name to register or retrieve as a singleton.
- $build : string|callable|null = null
-
Optional. A callable or a string representing the logic to build the instance. If null, the default constructor will be used.
Tags
Return values
mixed —The singleton instance of the specified class.
env()
Retrieves the value of an environment variable.
env(string $var[, mixed $default = null ]) : mixed
This function checks the $_ENV
superglobal for the specified variable
and returns its value if it exists. If the variable is not set, the
provided default value will be returned instead.
Parameters
- $var : string
-
The name of the environment variable to retrieve.
- $default : mixed = null
-
The default value to return if the environment variable is not set. Defaults to null.
Return values
mixed —The value of the environment variable, or the default value if the variable is not set.
resourcesDirectory()
Retrieves the path to the resources directory.
resourcesDirectory() : string
Return values
string —The absolute path to the resources directory.
config()
Retrieve a configuration value by its key.
config(string $key[, mixed $default = null ]) : mixed
This function fetches a configuration value from the application's configuration repository. If the specified key does not exist, a default value can be returned.
Parameters
- $key : string
-
The configuration key to retrieve.
- $default : mixed = null
-
The default value to return if the key does not exist. Defaults to null.
Return values
mixed —The configuration value associated with the key, or the default value if the key does not exist.
session()
Retrieve the current session instance.
session() : Session
This function provides access to the session instance managed by the application.
Return values
Session —The current session instance.
error()
Retrieves the first error message for a specific field from the session.
error(string $field) : string|null
This function accesses the session to fetch error messages stored under
a predefined key. If there are multiple error messages for the given field,
only the first one is returned. If no errors exist for the field, null
is returned.
Parameters
- $field : string
-
The name of the field for which to retrieve the error message.
Return values
string|null —The first error message for the specified field, or null
if no errors exist.
old()
Retrieve old input data for a given field from the session.
old(string $field) : mixed|null
This function fetches the value of a specific field from the old input data stored in the session. If the field does not exist, it returns null.
Parameters
- $field : string
-
The name of the field to retrieve old input data for.
Return values
mixed|null —The value of the old input data for the specified field, or null if not found.
snake_case()
Converts a given string to snake_case.
snake_case(string $str) : string
This function transforms a camelCase or PascalCase string into snake_case by inserting underscores before uppercase letters and converting all characters to lowercase.
Parameters
- $str : string
-
The input string to be converted.
Return values
string —The converted string in snake_case format.