Problem Storing Rich Text Fields and attachments with livewire
surencool4 opened this issue · 2 comments
surencool4 commented
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')
];
}
asadghazanfary commented
Majidkadi commented
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')