1. Go to this page and download the library: Download anil/file-picker 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/ */
anil / file-picker example snippets
namespace App\Livewire;
use Livewire\Attributes\On;
use Livewire\Component;
class PostForm extends Component
{
public array $selectedMedia = [];
#[On('filesSelected')]
public function handleFilesSelected(array $selected, string $inputName): void
{
// $selected is an array of media IDs
$this->selectedMedia = $selected;
}
public function render()
{
return view('components.post-form');
}
}
#[On('filesSelected')]
public function onFilesSelected(array $selected, string $inputName): void
{
// $selected is an array of media IDs (int)
// $inputName is the picker's `input-name` prop
$this->selectedIds = $selected;
}
#[On('file-picker-selected')]
public function onFilePickerSelected(array $payload): void
{
// keys: selected, inputName, inputId, formId, multiple, autoSubmit, callbackFunction
$this->selectedIds = $payload['selected'];
}
$this->setUploadError('Quota exceeded — contact your administrator.');
namespace App\Auth;
use Anil\LivewireFilePicker\Contracts\FilePickerAuthorizationInterface;
class MediaAuthorization implements FilePickerAuthorizationInterface
{
public function canViewLibrary(): bool { return auth()->check(); }
public function canUpload(): bool { return auth()->user()?->can('upload-media') ?? false; }
public function canDelete(int $mediaId): bool { return auth()->user()?->can('delete-media') ?? false; }
public function canEditAlt(int $mediaId): bool { return auth()->check(); }
}
namespace App\Filters;
use Anil\LivewireFilePicker\Contracts\CustomFilter;
use Illuminate\Database\Eloquent\Builder;
class MediaFilter implements CustomFilter
{
public function apply(Builder $query, array $filters): Builder
{
if (!empty($filters['tag'])) $query->where('tag', $filters['tag']);
if (!empty($filters['featured'])) $query->where('featured', true);
return $query;
}
}