Commit 94c9204d authored by Sylvain's avatar Sylvain

Ajout du helper public_folder_to_urls

parent 8d2a3223
......@@ -56,6 +56,7 @@ Laravel 5.8 uses autoload files, so doesn't require you to manually add the Serv
- [calc_increase_percent](#calc_increase_percent)
- [mixte_get](#mixte_get)
- [mixte_get_multi](#mixte_get_multi)
- [get_urls_from_public_folder](#get_urls_from_public_folder)
......@@ -271,6 +272,16 @@ $price = mixte_get_multi($source, $getters, $default = null);
```
#### `public_folder_to_urls()`
La fonction `public_folder_to_urls()` récupère une colelction d'url de fichiers à partir d'un chemin public relatif
```php
$urls = public_folder_to_urls("upload/folder/");
// Collection(['http://domain.tld/upload/folder/images1.png', 'http://domain.tld/upload/folder/images2.png'])
```
## Security
......
......@@ -24,8 +24,5 @@
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"laravel/framework": "5.8.x"
}
"prefer-stable": true
}
......@@ -3,7 +3,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Facades\File;
if ( !function_exists('calc_increase_percent')) {
......@@ -121,3 +121,30 @@ if ( !function_exists('mixte_get_multi')) {
return $datas;
}
}
if ( !function_exists('public_folder_to_urls')) {
/**
* Récupère une collection d'url de fichier depuis un dossier public
*
* @param string $public_path
* @return Collection
*/
function public_folder_to_urls($public_path)
{
$files_path = collect();
if (!empty($public_path)) {
$path = public_path($public_path);
$files = File::files($path);
$base_path = public_path();
foreach ($files as $file) {
$url = str_replace($base_path, url('/'), $file->getPathName());
$files_path->push($url);
}
}
return $files_path;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment