From 994e61b8d1a08140b4e9c2e091b3d998af2d152e Mon Sep 17 00:00:00 2001 From: raccoon254 Date: Fri, 9 Aug 2024 07:31:39 +0300 Subject: [PATCH] Added customization option --- app/Livewire/BlogMaker.php | 53 ++------- resources/views/blogs/create.blade.php | 145 ++++++++----------------- resources/views/blogs/layout.blade.php | 6 +- 3 files changed, 61 insertions(+), 143 deletions(-) diff --git a/app/Livewire/BlogMaker.php b/app/Livewire/BlogMaker.php index 53e058a..caac560 100644 --- a/app/Livewire/BlogMaker.php +++ b/app/Livewire/BlogMaker.php @@ -2,62 +2,33 @@ namespace App\Livewire; -use App\Services\MarkdownParser; -use Illuminate\Http\RedirectResponse; -use Illuminate\View\View; +use Livewire\Attributes\On; +use Livewire\Attributes\Validate; use Livewire\Component; -use Livewire\WithFileUploads; use App\Models\Blog; -use App\Models\User; -use App\Models\Image; use Illuminate\Support\Str; -use Illuminate\Support\Facades\Storage; +use Illuminate\Http\RedirectResponse; +use Illuminate\View\View; +use Illuminate\Support\Facades\Auth; class BlogMaker extends Component { - use WithFileUploads; - public $title; public $content = ''; - public $markdownContent = ''; - public $tempImage; - - protected $rules = [ - 'title' => 'required|min:6', - 'content' => 'required', - ]; - - public function updatedContent(): void - { - $this->parseTextToMarkdown($this->content); - } - - public function parseTextToMarkdown($content): void - { - $parser = new MarkdownParser(); - $this->markdownContent = $parser->parse($content); - } - - - public function uploadImage() - { - // Implement image upload logic here - Image::create([ - //TODO: Get the blog ID, - 'blog_id' => 1, - 'path' => $this->tempImage->store('images', 'public'), - ]); - } + public $contentHtml; public function saveBlog(): RedirectResponse { - $this->validate(); + $this->validate([ + 'title' => 'required|min:6', + 'content' => 'required|min:6', + ]); $blogData = [ 'title' => $this->title, - 'content' => $this->markdownContent, + 'content' => $this->content, // Storing HTML content directly 'slug' => Str::slug($this->title), - 'user_id' => auth()->id(), + 'user_id' => Auth::id(), ]; $blog = Blog::create($blogData); diff --git a/resources/views/blogs/create.blade.php b/resources/views/blogs/create.blade.php index e7bbaa9..15bf2a0 100644 --- a/resources/views/blogs/create.blade.php +++ b/resources/views/blogs/create.blade.php @@ -1,108 +1,55 @@ -
-
-
- - - - - - - - - -
- +
+
+ + @error('title') {{ $message }} @enderror
- -
-

Preview:

- - {{-- AS inner html - --}} -
-
+
+
+ @error('content') {{ $message }} @enderror
-
- + const quill = new Quill('#editor', { + theme: 'snow', + modules: { + toolbar: toolbarOptions + } + }); + + saveButton.addEventListener('click', () => { + @this. + set('content', quill.root.innerHTML); + @this. + saveBlog(); + }); + + + @endscript +
diff --git a/resources/views/blogs/layout.blade.php b/resources/views/blogs/layout.blade.php index f402dd1..45343e6 100644 --- a/resources/views/blogs/layout.blade.php +++ b/resources/views/blogs/layout.blade.php @@ -15,8 +15,8 @@ @vite(['resources/css/app.css', 'resources/js/app.js']) - - + +
@@ -26,7 +26,7 @@
-
+
{{ $slot }}