better file password implementation

This commit is contained in:
2024-04-25 18:40:40 +10:00
parent c702253837
commit 39609edc9e
6 changed files with 19 additions and 5 deletions

View File

@@ -72,6 +72,13 @@ class MediaController extends Controller
}
$media = $media->paginate($perPage)->onEachSide(1);
// Transform the 'password' field of each item in the collection
$media->getCollection()->transform(function ($item) {
$item->password = $item->password ? 'yes' : null;
return $item;
});
return $media;
}

View File

@@ -54,8 +54,7 @@ class Media extends Model
* @var array
*/
protected $casts = [
'variants' => 'array',
'password' => 'hashed'
'variants' => 'array'
];
/**

View File

@@ -10,7 +10,11 @@ trait HasFiles
{
public function files($collection = null)
{
// return $this->morphToMany(Media::class, 'mediable')
// ->wherePivot('collection', $collection);
return $this->morphToMany(Media::class, 'mediable')
->selectRaw("*, CASE WHEN password IS NULL THEN NULL ELSE 'yes' END AS password")
->wherePivot('collection', $collection);
}