laravel-trix icon indicating copy to clipboard operation
laravel-trix copied to clipboard

Problem Storing Rich Text Fields and attachments with livewire

Open surencool4 opened this issue 3 years ago • 2 comments

create.blade.php {{ __('Save Page') }}

    <x-slot name="content">
        <div class="mt-4">
            <x-jet-label for="title" value="{{ __('Title') }}" />
            <x-jet-input id="title" class="block mt-1 w-full" type="text" wire:model.debounce.800ms="title" />
            @error('title') <span class="error">{{ $message }}</span> @enderror
        </div>
        <div class="mt-4">
            <x-jet-label for="title" value="{{ __('Slug') }}" />
            <div class="mt-1 flex rounded-md shadow-sm">
                <span class="inline-flex dark:bg-black dark:text-white items-center px-3 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 text-gray-500 text-sm">
                    {{ url('') }}
                </span>
                <input wire:model="slug" class="form-input dark:bg-black dark:text-white flex-1 block w-full rounded-none rounded-r-md  transition duration-150 ease-in-out sm:text-sm sm:leading-5" placeholder="url-slug">
            </div>
            @error('slug') <span class="error">{{ $message }}</span> @enderror
        </div>
      


        <div class="mt-4" >
            <x-jet-label for="content" value="{{ __('Content') }}" />
            <div class="rounded-md shadow-sm">
                    <div wire:ignore>
                        @trix(\App\Page::class, 'content')
                    </div>
                </div>                  

            </div>
            @error('content') <span class="error">{{ $message }}</span> @enderror
        </div>   
        
    </x-slot>

    <x-slot name="footer">
        <x-jet-secondary-button wire:click="$toggle('modalFormVisible')" wire:loading.attr="disabled">
            {{ __('Cancel') }}
        </x-jet-secondary-button>

            <x-jet-button class="ml-2" wire:click="create" wire:loading.attr="disabled">
                {{ __('Create') }}
            </x-jet-danger-button>
      
    </x-slot>
</x-jet-dialog-modal>

Livewire/Page.php public function create() { $this->validate(); $this->post = Page::create($this->modelData()); $this->modalFormVisible = false; $this->reset(); } public function modelData() { return [ 'title' => $this->title, 'slug' => $this->slug, 'content' => $this->content, 'page-trixFields' => request('page-trixFields'),
'attachment-post-trixFields' => request('attachment-post-trixFields') ]; }

surencool4 avatar Jul 11 '21 08:07 surencool4

hi @surencool4

problem solved?

If you solve the problem, can you explain it to me?

thanks

asadghazanfary avatar Oct 14 '21 13:10 asadghazanfary

Hi, I think you have an error in your code. 'attachment-post-trixFields' => request('attachment-post-trixFields') I guess it should be 'page' like this: 'attachment-page-trixFields' => request('attachment-page-trixFields')

Majidkadi avatar Oct 15 '21 22:10 Majidkadi