spatie/laravel-medialibrary-pro-app

Amount of requests grows until reloading the page

Closed this issue · 1 comments

I have no idea how to document this in a way that you could easily help me. I will try my best to explain and will provide as much information as possible.
I've built a livewire component with livewire children. The children are called OfferTemplate. This all works fine. I can change the attributes of the OfferTemplates. Now I added a file upload mechanism with medialibrary-pro.
After this, my OfferTemplate components are generating much more requests than before. The amount of requests grows linear as long I do not reload the page in my browser. Also, when I delete a OfferTemplate I will get 404s when I have an uploaded file in them. When I remove the file upload part in the blade template, everything works fine again.

Since one picture says more than a thousand words, here is a demonstration: https://youtu.be/ucYM58yB9Wc

This is the livewire component:

namespace App\Http\Livewire\Experte;

use App\Models\BillingMode;
use App\Models\OrderType;
use App\Rules\GermanNumeric;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Livewire\Component;
use Spatie\MediaLibraryPro\Http\Livewire\Concerns\WithMedia;

class OfferTemplate extends Component
{
    use WithMedia;

    public $mediaComponentNames = ['currentDocument'];

    public $currentDocument;

    public $offerTemplate;

    public function mount(orderType $orderType): void
    {
        $this->offerTemplate = Auth::user()->offerTemplatesBuilder()->whereTypeId($orderType->id)->first();

        if ($this->offerTemplate === null) {
            $this->offerTemplate = new \App\Models\OfferTemplate();
            $this->offerTemplate->user_id = Auth::id();
            $this->offerTemplate->type_id = $orderType->id;
            $this->offerTemplate->brutto = 0;
        }
    }

    public function saveOfferTemplate()
    {
       
        $this->validate();
       
        $this->offerTemplate->save();
        $this->offerTemplate->addFromMediaLibraryRequest($this->currentDocument)->toMediaCollection('currentDocument');
        //$this->offerTemplate->syncFromMediaLibraryRequest($this->currentDocument)->toMediaCollection('currentDocument');

        $this->dispatchBrowserEvent('show-toast', ['message' => 'Angebotsvorlage wurde gespeichert']);
        $this->dispatchBrowserEvent('modal-new-close');
        $this->dispatchBrowserEvent("offer-template-{$this->offerTemplate->type_id}-is-complete");
        $this->dispatchBrowserEvent("activate-order-type-{$this->offerTemplate->type_id}");
        $this->clearMedia();
    }

    public function deleteOfferTemplate()
    {
        $this->clearMedia();

        $this->dispatchBrowserEvent('show-toast', ['message' => 'Angebotsvorlage wurde gelöscht']);
        $this->dispatchBrowserEvent('modal-new-close');
        $this->dispatchBrowserEvent("offer-template-{$this->offerTemplate->type_id}-is-deleted");
        $this->offerTemplate->delete();
    }


    public function render()
    {
        return view('livewire.experte.offer-template');
    }
}

this is the model:

namespace App\Models;

use App\Casts\GermanNumeric;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class OfferTemplate extends Model implements HasMedia
{
    use HasFactory;
    use InteractsWithMedia;

    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('currentDocument')->singleFile();
    }

}

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.