Forge Helpers
Overview
Forge Framework provides a collection of helper classes that simplify common tasks and provide utility functions for your application. These helpers are designed to be easy to use and can be accessed statically throughout your application.
App Helper
The App helper provides convenient methods to access core application services and components:
use Forge\Core\Helpers\App;
// Get application environment
$env = App::environment();
// Access service container
$service = App::make('ServiceName');
// Get configuration values
$value = App::config('app.key');
// Access storage service
$storage = App::storage();
// Get cache instance
$cache = App::cache();
Asset Helper
The Asset helper manages application assets and generates proper URLs:
use Forge\Core\Helpers\Asset;
// Generate URL for CSS file
$cssUrl = Asset::css('main.css');
// Generate URL for JavaScript file
$jsUrl = Asset::js('app.js');
// Generate URL for image
$imageUrl = Asset::image('logo.png');
// Generate URL for any asset
$assetUrl = Asset::url('files/document.pdf');
Date Helper
The Date helper provides methods for date and time manipulation:
use Forge\Core\Helpers\Date;
// Get current timestamp
$now = Date::now();
// Format date
$formatted = Date::format('Y-m-d');
// Add days to date
$future = Date::addDays(5);
// Compare dates
$diff = Date::diff('2023-01-01', '2023-12-31');
Debug Helper
The Debug helper provides debugging utilities:
use Forge\Core\Helpers\Debug;
// Dump variable
Debug::dump($variable);
// Dump and die
Debug::dd($variable);
// Get debug backtrace
$trace = Debug::backtrace();
Framework Helper
The Framework helper provides access to framework-specific functionality:
use Forge\Core\Helpers\Framework;
// Get framework version
$version = Framework::version();
// Check if running in console
$isConsole = Framework::isConsole();
// Get framework root path
$path = Framework::path();
Hash Helper
The Hash helper provides secure hashing functionality:
use Forge\Core\Helpers\Hash;
// Create password hash
$hash = Hash::make('password');
// Verify password
$valid = Hash::verify('password', $hash);
// Generate random string
$random = Hash::random(16);
Path Helper
The Path helper manages application paths:
use Forge\Core\Helpers\Path;
// Get application root path
$root = Path::root();
// Get storage path
$storage = Path::storage('files');
// Get public path
$public = Path::public('assets');
// Get config path
$config = Path::config();
Redirect Helper
The Redirect helper manages HTTP redirects:
use Forge\Core\Helpers\Redirect;
// Redirect to URL
Redirect::to('/dashboard');
// Redirect with flash message
Redirect::with('success', 'Operation completed')->to('/home');
// Redirect back
Redirect::back();
// Redirect with input
Redirect::withInput()->to('/form');
Strings Helper
The Strings helper provides string manipulation methods:
use Forge\Core\Helpers\Strings;
// Convert to camel case
$camel = Strings::camel('hello_world');
// Convert to snake case
$snake = Strings::snake('helloWorld');
// Generate slug
$slug = Strings::slug('Hello World');
// Random string
$random = Strings::random(10);
Transform Helper
The Transform helper provides data transformation utilities:
use Forge\Core\Helpers\Transform;
// Transform array to object
$object = Transform::toObject($array);
// Transform object to array
$array = Transform::toArray($object);
// Transform to JSON
$json = Transform::toJson($data);
UUID Helper
The UUID helper generates and validates UUIDs:
use Forge\Core\Helpers\UUID;
// Generate UUID
$uuid = UUID::generate();
// Validate UUID
$valid = UUID::isValid($uuid);
// Generate UUID v4
$uuidV4 = UUID::v4();
View Helper
The View helper provides methods for rendering views and managing view-related functionality:
use Forge\Core\Helpers\View;
// Render a view
$html = View::render('pages.home');
// Render with data
$html = View::render('user.profile', ['user' => $user]);
// Set view layout
View::setLayout('layouts.main');
// Share data with all views
View::share('siteName', 'My Website');
// Check if view exists
$exists = View::exists('pages.about');