PHP code example of gheith3 / filament-file-view-entry

1. Go to this page and download the library: Download gheith3/filament-file-view-entry library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gheith3 / filament-file-view-entry example snippets


use gheith3\FileViewEntryPlugin\FileViewEntryPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(FileViewEntryPlugin::make());
}

use gheith3\FileViewEntryPlugin\Infolists\Components\FileViewEntry;

// Single file - opens in modal when clicked
FileViewEntry::make('file_path')
    ->downloadable();

// Multiple files in grid layout
FileViewEntry::make('attachments')
    ->grid(4)
    ->downloadable();

FileViewEntry::make('documents')
    ->grid(3)
    ->titleKey('title')        // Default: 'name'
    ->pathKey('path')          // Default: 'file_path'
    ->dateKey('uploaded_at')   // Default: null (hidden)
    ->downloadable();

FileViewEntry::make('files')
    ->grid(2)  // 2 columns on all screens
    ->grid(3)  // 2 cols mobile, 3 cols tablet+
    ->grid(4)  // 2 cols mobile, 3 tablet, 4 desktop
    ->grid(5)  // 2 cols mobile, 3 tablet, 4 desktop, 5 xl
    ->grid(6)  // 2 cols mobile, 3 tablet, 4 desktop, 6 xl

// In your resource
public static function infolist(Infolist $infolist): Infolist
{
    return $infolist
        ->schema([
            FileViewEntry::make('uploadedFiles') // relationship name
                ->label('Attachments')
                ->grid(6)
                ->downloadable(),
        ]);
}

$data = [
    ['title' => 'Contract.pdf', 'document_path' => 'docs/contract.pdf'],
    ['title' => 'Photo.jpg', 'document_path' => 'images/photo.jpg'],
];

FileViewEntry::make('customData')
    ->titleKey('title')
    ->pathKey('document_path')
    ->grid(2);

FileViewEntry::make('attachments')
    ->grid(4)
    ->downloadable();

FileViewEntry::make('attachments')
    ->showAsLink(true)         // Compact list view
    ->downloadable();

FileViewEntry::make('attachments')
    ->asModal(false)           // Display content inline
    ->downloadable()
    ->grid(2);

FileViewEntry::make('attachments')
    ->asModal(false)           // Display content inline
    ->withModalEye(true)       // Add eye button for modal preview
    ->downloadable()
    ->grid(2);

FileViewEntry::make('attachments')
    ->contained(false)         // Remove background/border
    ->grid(4);

FileViewEntry::make('attachments')
    ->lazyLoad(true)           // Enable lazy loading for images
    ->grid(4);

FileViewEntry::make('attachments')
    ->showFileSize(true)       // Show file size (e.g., "2.5 MB")
    ->grid(4);

FileViewEntry::make('attachments')
    ->showFileCount(true)      // Show "3 files" badge
    ->grid(4);

FileViewEntry::make('attachments')
    ->loadingSkeleton(true)    // Show loading skeleton
    ->grid(4);

FileViewEntry::make('attachments')
    ->copyable(true)           // Add copy link button
    ->downloadable()
    ->grid(4);

FileViewEntry::make('attachments')
    ->customIcons([
        'psd' => 'heroicon-o-paint-brush',    // By extension
        'ai' => 'heroicon-o-swatch',
        'image' => 'heroicon-o-camera',       // By file type
        'video' => 'heroicon-o-film',
    ])
    ->grid(4);