Skip to content

Commit

Permalink
update files
Browse files Browse the repository at this point in the history
  • Loading branch information
juancristobalgd1 authored Dec 26, 2023
1 parent fbbba84 commit 766eec0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,17 +961,19 @@ function class_basename($class)
if (!function_exists('asset')) {

/**
* Generate the URL of a resource using the path relative to the resource directory
*
* @param string $path Path relative to the resource directory
* @param bool $versioned Add a version hash to the filename
* @param bool $secure Force the use of HTTPS in the URL
* @return string Full URL of the resource.
* Generate the URL for an asset.
*
* This function takes a relative path to an asset and combines it with the base URL of the application,
* producing the full URL to the asset. It ensures proper handling of directory separators.
*
* @param string $path The relative path to the asset.
* @param string|null $basePath The base URL of the application (optional). If not provided, it uses an empty string.
* @return string The full URL to the asset.
*/
function asset(string $path, $basePath = null): string
function asset(string $path, ?string $basePath = null): string
{
// Get the URL base of your application from the configuration or as you prefer.
$baseUrl = $basePath ? $basePath : '';
$baseUrl = $basePath ?? '';

// Combines the base URL with the relative path of the resource.
$url = rtrim($baseUrl, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
Expand Down

0 comments on commit 766eec0

Please sign in to comment.