Skip to content

[Feature] File Upload Support #1

@devalade

Description

@devalade

Description

Add support for file and image uploads in generated CRUDs.

Proposed Syntax

php artisan crudify:generate Product \
  --fields="name:string,photo:file,images:file:multiple,brochure:file:pdf"

Generated Components

  • Migration: Add photo as string (path storage) or text (JSON array for multiple)
  • Model: Handle file casts and accessors
  • Livewire Create/Edit: Add <input type="file" wire:model="photo"> with @livewireScripts handling
  • Index: Show thumbnail previews in table
  • Show: Display full image or download link
  • Factory: Use UploadedFile::fake()->image() for testing

Key Considerations

  • Disk configuration (local/s3)
  • Multiple file uploads
  • File type validation in form requests
  • Cleanup on delete/update

Example

// In Livewire Create component
#[Validate(['photo' => 'nullable|image|max:2048'])]
public $photo;

public function save(): void
{
    $validated = $this->validate();
    
    if ($this->photo) {
        $validated['photo'] = $this->photo->store('products', 'public');
    }
    
    Product::create($validated);
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions