1. Go to this page and download the library: Download qisti/smart-ui-qisti 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/ */
public function store(Request $request)
{
$data = $request->validate([
'documents' => [' foreach ($data['documents'] as $file) {
$file->store('documents', 'public');
}
}
use Livewire\WithFileUploads;
class UploadDocuments extends Component
{
use WithFileUploads;
public $documents = [];
public function save()
{
$this->validate([
'documents' => [''documents');
}
}
Schema::create('letter_documents', function (Blueprint $table) {
$table->id();
$table->foreignId('letter_id')->constrained()->cascadeOnDelete();
$table->string('path'); // where the file lives on the disk
$table->string('filename'); // the name to show in the UI
$table->unsignedInteger('sort_order')->default(0);
$table->timestamps();
});
$data = $request->validate([
// The user may keep a saved file and upload nothing new — so "' => ['array'],
'documents_existing.*' => ['string'],
'documents_order' => ['array'],
'documents_order.*' => ['string'],
]);
$kept = $data['documents_existing'] ?? [];
// Scoped to this letter, so a forged id cannot reach another record's rows.
$letter->documents()->whereNotIn('id', $kept)->get()->each(function ($doc) {
Storage::disk('public')->delete($doc->path);
$doc->delete();
});
$uploads = $request->file('documents', []);
foreach ($data['documents_order'] ?? [] as $position => $token) {
[$kind, $ref] = array_pad(explode(':', $token, 2), 2, null);
if ($kind === 'existing') {
$letter->documents()->whereKey($ref)->update(['sort_order' => $position]);
} elseif ($kind === 'new' && isset($uploads[$ref])) {
$letter->documents()->create([
'path' => $uploads[$ref]->store('documents', 'public'),
'filename' => $uploads[$ref]->getClientOriginalName(),
'sort_order' => $position,
]);
}
}
public array $documents = [];
public array $keptDocuments = [];
public array $documentOrder = [];
public function mount(Letter $letter)
{
// Seed both: if the user removes nothing, the browser never writes to these
// properties, and empty ones would read as "delete everything".
$this->keptDocuments = $letter->documents->pluck('id')->map(strval(...))->all();
$this->documentOrder = array_map(fn ($id) => "existing:{$id}", $this->keptDocuments);
}