better file password implementation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ class Media extends Model
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'variants' => 'array',
|
||||
'password' => 'hashed'
|
||||
'variants' => 'array'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user