Helpers
Introduction
DreamFork incorporates a range of global "helper" PHP functions. While many of these functions serve internal purposes within the framework, you are welcome to leverage them in your own applications if you find them beneficial.
Available Methods
DreamFork incorporates a range of global "helper" PHP functions. While many of these functions serve internal purposes within the framework, you are welcome to leverage them in your own applications if you find them beneficial.
Array & Objects
DreamFork utilizes the Arr class from Laravel for handling arrays. The documentation for this class is accessible at https://laravel.com/docs/10.x/helpers#arrays-and-objects-method-list
Paths
URLs
Miscellaneous
app absolute_path class_basename collect config e env kernel load logger request response router throw_if validator view
Paths
app_path()
The app_path function returns the fully qualified path to your application's app directory. You may also use the app_path function to generate a fully qualified path to a file relative to the application directory:
$path = app_path('Controllers/UserController.php');
base_path()
The base_path returns the fully qualified path to your application's root directory. You may also use the base_path function to generate a fully qualified path to a given file relative to the project root directory.
config_path()
The config_path function returns the fully qualified path to your application's config directory. You may also use the config_path function to generate a fully qualified path to a given file within the application's configuration directory.
database_path()
The database_path function returns the fully qualified path to your application's database directory. You may also use the database_path function to generate a fully qualified path to a given file within the database directory.
public_path()
The public_path function returns the fully qualified path to your application's public directory. You may also use the public_path function to generate a fully qualified path to a given file within the public directory.
resource_path()
The resource_path function returns the fully qualified path to your application's resource directory. You may also use the resource_path function to generate a fully qualified path to a file relative to the application directory:
storage_path()
The storage_path function returns the fully qualified path to your application's storage directory. You may also use the storage_path function to generate a fully qualified path to a file relative to the application directory:
URLs
asset()
The asset function generates a URL for an asset using the current scheme of the request (HTTP or HTTPS):
$url = asset('css/global.css'); // https://example.com/css/global.css
url()
The url function generates a fully qualified URL to the given path. If no path is provided, an Framework\Services\URL\UrlGenerator instance is returned.
$url = url('user/profile'); // https://example.com/user/profile
Miscellaneous
app()
The app function returns the service container instance.
absolute_path()
The absolute_path function converts a given path to its absolute form:
echo absolute_path(storage_path("public/someFile.png")); // /home/www/example/storage/public/someFile.png
class_basename()
The class_basename function returns the class "basename" of the given object or class name.
collect()
The collect function creates a collection instance from the given value.
config()
The config function gets the value of a configuration variable. The configuration values may be accessed using "dot" syntax, which includes the name of the file and the option you wish to access. A default value may be specified and is returned if the configuration option does not exist:
$value = config('app.locale', 'en');
e()
The e function returns encoded HTML special characters in a string.
env()
The env function retrieves the value of an environment variable or returns a default value:
kernel()
The kernel function returns the Framework\Http\Kernel instance.
load()
The load function loads a specified PHP file if it exists, otherwise throws exception.
logger()
The logger function returns the App\Exceptions\Handler instance.
request()
The request function returns the current request instance.
response()
The response function creates a response instance or obtains an instance of the response factory:
router()
The router function return the Framework\Http\Router instance.
throw_if()
The throw_if function throws the given exception if the given condition is true:
throw_if($collection->isEmpty(), new Exception('Collection cannot be empty!'));
validator()
The validator function creates a new validator instance with the given arguments. You may use it as an alternative to the Validator facade.
view()
The view function retrieves a view instance.
Other Utilities
Dates
Dreamfork includes Carbon, a robust library for date and time manipulation. You can instantiate a new Carbon instance using the Carbon\Carbon class. For a comprehensive understanding of Carbon and its functionalities, we recommend referring to the official Carbon documentation.
use Carbon\Carbon;
$now = Carbon::now();