31 lines
754 B
PHP
31 lines
754 B
PHP
<?php
|
|
|
|
namespace App\Http\Services;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class Media
|
|
{
|
|
protected $mediaType = ['image/jpeg','image/png','image/webp','image/svg+xml'];
|
|
|
|
public function getAllMedia()
|
|
{
|
|
$list_files = Storage::allFiles('Upload');
|
|
|
|
$pages = \request()->get('pages') ? \request()->get('pages') : 1;
|
|
$images = [];
|
|
$limit = 20;
|
|
$offset = ($pages - 1) * $limit;
|
|
foreach ($list_files as $item) {
|
|
if (in_array(Storage::mimeType($item),$this->mediaType)) {
|
|
$images[] = $item;
|
|
}
|
|
}
|
|
if ($offset > count($images))
|
|
{
|
|
return [];
|
|
}
|
|
return array_slice(array_reverse($images),$offset,$limit);
|
|
}
|
|
}
|