Mar*_*ury 7 php laravel laravel-filament
我想知道是否有任何方法可以在filamentPHP管理面板中显示私人上传的文件。只有经过身份验证的用户才能看到它,因为它不在 Laravel 的公共存储文件夹中。他们的文档似乎不包含它。
小智 0
您可以通过Sushi套餐来实现这一点。
应用程序/模型/PrivateFilesWrapper.php
class PrivateFilesWrapper extends Model
{
use HasFactory;
use Sushi;
public function getRows(): array
{
$files = Storage::disk('private_disk')->allFiles();
$rows = Arr::map($files, function (string $value, string $key) {
$size = Storage::disk('private_disk')->size($value);
$date = Storage::disk('private_disk')->lastModified($value);
return [
'name' => $value,
'date' => $date,
'size' => $size,
];
});
return $rows;
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序/灯丝/页面/Private.php
class Private extends Page implements HasTable
{
use InteractsWithTable;
protected static string $view = 'filament.pages.private-files';
public function table(Table $table): Table
{
return $table
->query(PrivateFilesWrapper::query())
->columns([
TextColumn::make('name'),
TextColumn::make('date'),
TextColumn::make('size'),
])
->actions([
DeleteAction::make('delete')
->action(fn ($record) => Storage::disk('private_disk')->delete($record->name)),
]);
}
}
Run Code Online (Sandbox Code Playgroud)
资源/视图/灯丝/页面/private-files.blade.php
<x-filament-panels::page>
{{ $this->table }}
</x-filament-panels::page>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
436 次 |
| 最近记录: |