feat: Allow for saving of articles
This commit is contained in:
parent
4954d8c389
commit
18e8c2c634
|
|
@ -52,8 +52,8 @@ class WriterController extends Controller
|
||||||
public function livePreview(Request $request): View
|
public function livePreview(Request $request): View
|
||||||
{
|
{
|
||||||
// Upload the file
|
// Upload the file
|
||||||
logger('hey', ['stuff' => request()->all()]);
|
//logger('hey', ['stuff' => request()->all()]);
|
||||||
sleep(2);
|
//sleep(2);
|
||||||
$header_image_path = $request->headerImage?->storeAs('header-image-previews');
|
$header_image_path = $request->headerImage?->storeAs('header-image-previews');
|
||||||
$article_empty = new Article();
|
$article_empty = new Article();
|
||||||
$article_empty->markdown_body = $request->get('markdown-body');
|
$article_empty->markdown_body = $request->get('markdown-body');
|
||||||
|
|
@ -75,4 +75,25 @@ class WriterController extends Controller
|
||||||
|
|
||||||
return view('shared.single-article', ['article' => $article]);
|
return view('shared.single-article', ['article' => $article]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function saveArticle(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$header_image_path = $request->headerImage?->storeAs('header-image-previews');
|
||||||
|
$article_empty = new Article();
|
||||||
|
$article_empty->markdown_body = $request->get('markdown-body');
|
||||||
|
$article_empty->convertMarkdownToMarkup();
|
||||||
|
|
||||||
|
Article::create([
|
||||||
|
'title' => $request->title ?? null,
|
||||||
|
'slug' => $request->slug ?? null,
|
||||||
|
'author_id' => auth()->user()->id,
|
||||||
|
'subtitle' => $request->subtitle ?? null,
|
||||||
|
'body' => $article_empty->body,
|
||||||
|
'published_at' => $request->get('publication-date') ?? null,
|
||||||
|
'header_image_url' => $header_image_path ?? null,
|
||||||
|
'markdown_body' => $request->get('markdown-body'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect(route('dashboard'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,8 @@ document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
|
|
||||||
<div id="page-body-container">
|
<div id="page-body-container">
|
||||||
<section id="new-article-form-container">
|
<section id="new-article-form-container">
|
||||||
<form id="new-article-form" method="POST" action="route('live_preview')">
|
<form id="new-article-form" method="POST" action="{{route('save_article')}}">
|
||||||
|
@csrf
|
||||||
<label for="publication-date">Publication Date</label>
|
<label for="publication-date">Publication Date</label>
|
||||||
<input id="publication-date" name="publication-date" type="datetime-local" class="affects-preview" />
|
<input id="publication-date" name="publication-date" type="datetime-local" class="affects-preview" />
|
||||||
<label for="title">Title</label>
|
<label for="title">Title</label>
|
||||||
|
|
@ -97,7 +98,7 @@ document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
<button
|
<button
|
||||||
id="htmx-preview-button"
|
id="htmx-preview-button"
|
||||||
data-hx-post="{{ route('live_preview') }}"
|
data-hx-post="{{ route('live_preview') }}"
|
||||||
data-hx-trigger="click, keyup changed delay:1500ms from:.affects-preview"
|
data-hx-trigger="click, keyup changed delay:1100ms from:.affects-preview"
|
||||||
data-hx-target="#true-container"
|
data-hx-target="#true-container"
|
||||||
data-hx-swap="innerHTML"
|
data-hx-swap="innerHTML"
|
||||||
data-hx-indicator="#preview-indicator"
|
data-hx-indicator="#preview-indicator"
|
||||||
|
|
|
||||||
|
|
@ -52,4 +52,5 @@ Route::middleware('auth')->group(function () {
|
||||||
Route::post('/logout', [WriterController::class, 'logout'])->name('logout');
|
Route::post('/logout', [WriterController::class, 'logout'])->name('logout');
|
||||||
Route::get('writer/new-article', [WriterController::class, 'newArticle'])->name('new_article');
|
Route::get('writer/new-article', [WriterController::class, 'newArticle'])->name('new_article');
|
||||||
Route::post('writer/live-preview', [WriterController::class, 'livePreview'])->name('live_preview');
|
Route::post('writer/live-preview', [WriterController::class, 'livePreview'])->name('live_preview');
|
||||||
|
Route::post('writer/save-article', [WriterController::class, 'saveArticle'])->name('save_article');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue