for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Thinktomorrow\AssetLibrary\Application;
use Thinktomorrow\AssetLibrary\Asset;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Thinktomorrow\AssetLibrary\Exceptions\FileNotAccessibleException;
use Thinktomorrow\AssetLibrary\HasAsset;
class DeleteAsset
{
/**
* Removes an asset completely.
*
* @param $ids
*/
public function delete($ids): void
if (is_array($ids)) {
foreach ($ids as $id) {
self::remove($id);
Thinktomorrow\AssetLibra...n\DeleteAsset::remove()
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
self::/** @scrutinizer ignore-call */
remove($id);
}
} else {
if (! $ids) {
return;
self::remove($ids);
public function remove($id)
if (! $id) {
return false;
if (! $asset = Asset::find($id)) {
$media = $asset->media;
/** @var Media $file */
foreach ($media as $file) {
$file_path = $file->getPath();
if (! is_file($file_path) || ! is_writable($file_path)) {
throw new FileNotAccessibleException();
$asset->delete();
* Removes all assets completely.
public function deleteAll(HasAsset $model): void
$model->assetRelation->each->delete();
assetRelation
Thinktomorrow\AssetLibrary\HasAsset
instanceof