Add bookmark editing backend

This commit is contained in:
Annika Backstrom 2024-05-26 14:41:28 +01:00
parent 1bbc1b9166
commit f73c8310a1
Signed by: annika
GPG Key ID: 3561F004DE1D9AFE
5 changed files with 26 additions and 13 deletions

View File

@ -10,7 +10,7 @@ A little project because I haven't made anything new in a while, I would like to
* [x] Bookmark permalink * [x] Bookmark permalink
* [x] Bookmark index * [x] Bookmark index
* [x] Bookmark pagination * [x] Bookmark pagination
* [ ] Editing * [x] Editing
* [ ] Tag cloud * [ ] Tag cloud
* [ ] Tag permalink * [ ] Tag permalink
* [ ] Multi-user support * [ ] Multi-user support

View File

@ -38,11 +38,11 @@ class BookmarkController extends Controller
/** /**
* Display the specified resource. * Display the specified resource.
*/ */
public function show(string $id) public function show(Bookmark $bookmark)
{ {
return view( return view(
'bookmarks.show', [ 'bookmarks.show', [
'bookmark' => $bookmark = Bookmark::findOrFail($id), 'bookmark' => $bookmark,
] ]
); );
} }
@ -50,12 +50,12 @@ class BookmarkController extends Controller
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
*/ */
public function edit(string $id) public function edit(Bookmark $bookmark)
{ {
return view( return view(
'bookmarks.edit', [ 'bookmarks.edit', [
'edit' => true, 'edit' => true,
'bookmark' => $bookmark = Bookmark::findOrFail($id), 'bookmark' => $bookmark,
] ]
); );
} }
@ -63,9 +63,18 @@ class BookmarkController extends Controller
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
*/ */
public function update(Request $request, string $id) public function update(Request $request, Bookmark $bookmark)
{ {
// $bookmark->title = $request->post('title');
$bookmark->description = $request->post('description', '');
$bookmark->href = $request->post('href');
$bookmark->save();
return redirect()->action(
[self::class, "show"], [
"bookmark" => $bookmark,
]
);
} }
/** /**

View File

@ -4,25 +4,26 @@
<p> <p>
<a href="{{ action('BookmarkController@index') }}">&larr; Back</a> <a href="{{ action('BookmarkController@index') }}">&larr; Back</a>
</p> </p>
<form action="post" class="form"> <form method="post" class="form" action="{{ action('BookmarkController@update', ['bookmark' => $bookmark]) }}">
@csrf
<div class="bookmark"> <div class="bookmark">
<div class="bookmark-title form-row"> <div class="bookmark-title form-row"g>
<label class="form-label" for="title"> <label class="form-label" for="title">
Title: Title:
</label> </label>
<input type="text" class="form-input" "name="title" value="{{ htmlentities($bookmark->title) }}"> <input type="text" class="form-input" name="title" value="{{ $bookmark->title }}">
</div> </div>
<div class="bookmark-href form-row form-row-stacked"> <div class="bookmark-href form-row form-row-stacked">
<label class="form-label" for="href"> <label class="form-label" for="href">
URL: URL:
</label> </label>
<input type="text" class="form-input" "name="href" value="{{ htmlentities($bookmark->href) }}"> <input type="text" class="form-input" name="href" value="{{ $bookmark->href }}">
</div> </div>
<div class="bookmark-description form-row form-row-stacked"> <div class="bookmark-description form-row form-row-stacked">
<label class="form-label" for="description"> <label class="form-label" for="description">
Description: Description:
</label> </label>
<textarea name="description" class="form-textarea">{{ htmlentities($bookmark->title) }}</textarea> <textarea name="description" class="form-textarea">{{ $bookmark->description }}</textarea>
</div> </div>
<div class="form-row align-right bookmark-actions"> <div class="form-row align-right bookmark-actions">
<a class="form-button" href="{{ action('BookmarkController@show', ['bookmark' => $bookmark]) }}">Cancel</a> <a class="form-button" href="{{ action('BookmarkController@show', ['bookmark' => $bookmark]) }}">Cancel</a>

View File

@ -2,7 +2,8 @@
<p class="bookmark-title"> <p class="bookmark-title">
{{ $bookmark->title }} {{ $bookmark->title }}
@action('index') @action('index')
<a href="/bookmarks/{{ $bookmark->id }}">#</a> <a href="{{ action('BookmarkController@show', $bookmark) }}">#</a>
<a href="{{ action('BookmarkController@edit', $bookmark) }}">e</a>
@endaction @endaction
</p> </p>
<p class="bookmark-href"><a href="{{ $bookmark->href }}">{{ $bookmark->href }}</a></p> <p class="bookmark-href"><a href="{{ $bookmark->href }}">{{ $bookmark->href }}</a></p>

View File

@ -8,4 +8,6 @@ Route::get(
return redirect()->action([BookmarkController::class, 'index']); return redirect()->action([BookmarkController::class, 'index']);
} }
); );
Route::resource('bookmarks', BookmarkController::class); Route::resource('bookmarks', BookmarkController::class);
Route::post('/bookmarks/{bookmark}', [BookmarkController::class, 'update']);