| Total Complexity | 10 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class AssetLibrary |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Removes one or more assets by their ids. |
||
| 11 | */ |
||
| 12 | 5 | public static function removeByIds($imageIds) |
|
| 24 | } |
||
| 25 | 5 | } |
|
| 26 | |||
| 27 | /** |
||
| 28 | * Removes one assets by id. |
||
| 29 | * It also checks if you have the permissions to remove the file. |
||
| 30 | * |
||
| 31 | * @param $imageIds |
||
| 32 | */ |
||
| 33 | 5 | public static function remove($id) |
|
| 34 | { |
||
| 35 | 5 | if (! $id) { |
|
| 36 | 1 | return false; |
|
| 37 | } |
||
| 38 | |||
| 39 | 4 | $asset = Asset::find($id)->first(); |
|
| 40 | 4 | $media = $asset->media; |
|
| 41 | |||
| 42 | 4 | foreach ($media as $file) { |
|
| 43 | 4 | if (! is_file(public_path($file->getUrl())) || ! is_writable(public_path($file->getUrl()))) { |
|
| 44 | 4 | return; |
|
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | 4 | $asset->delete(); |
|
| 49 | 4 | } |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Returns a collection of all the assets in the library. |
||
| 53 | * @return \Illuminate\Support\Collection |
||
| 54 | */ |
||
| 55 | 7 | public static function getAllAssets(): Collection |
|
| 58 | } |
||
| 59 | } |
||
| 60 |