-
composer.json
Open in GitHub{ // "require": { "php": "^7.3", // "spatie/laravel-medialibrary": "^8.7" }, // }
-
app/Ticket.php
Open in GitHubuse App\Traits\Auditable; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class Ticket extends Model implements HasMedia { use SoftDeletes, InteractsWithMedia, Auditable; // public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->width(50)->height(50); } // }
-
app/Http/Controllers/Admin/TicketsController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Requests\StoreTicketRequest; use App\Ticket; class TicketsController extends Controller { // public function store(StoreTicketRequest $request) { $ticket = Ticket::create($request->all()); foreach ($request->input('attachments', []) as $file) { $ticket->addMedia(storage_path('tmp/uploads/' . $file))->toMediaCollection('attachments'); } return redirect()->route('admin.tickets.index'); } // }