diff --git a/README.md b/README.md index 505c201..813e43e 100644 --- a/README.md +++ b/README.md @@ -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 index * [x] Bookmark pagination -* [ ] Editing +* [x] Editing * [ ] Tag cloud * [ ] Tag permalink * [ ] Multi-user support diff --git a/app/Http/Controllers/BookmarkController.php b/app/Http/Controllers/BookmarkController.php index 039b645..73685c5 100644 --- a/app/Http/Controllers/BookmarkController.php +++ b/app/Http/Controllers/BookmarkController.php @@ -38,11 +38,11 @@ class BookmarkController extends Controller /** * Display the specified resource. */ - public function show(string $id) + public function show(Bookmark $bookmark) { return view( '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. */ - public function edit(string $id) + public function edit(Bookmark $bookmark) { return view( 'bookmarks.edit', [ 'edit' => true, - 'bookmark' => $bookmark = Bookmark::findOrFail($id), + 'bookmark' => $bookmark, ] ); } @@ -63,9 +63,18 @@ class BookmarkController extends Controller /** * 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, + ] + ); } /** diff --git a/resources/views/bookmarks/edit.blade.php b/resources/views/bookmarks/edit.blade.php index 2ac7799..f1da968 100644 --- a/resources/views/bookmarks/edit.blade.php +++ b/resources/views/bookmarks/edit.blade.php @@ -4,25 +4,26 @@

← Back

-
+ + @csrf
-
+
- +
- +
- +
Cancel diff --git a/resources/views/components/bookmark.blade.php b/resources/views/components/bookmark.blade.php index 4956fa4..fed4b9d 100644 --- a/resources/views/components/bookmark.blade.php +++ b/resources/views/components/bookmark.blade.php @@ -2,7 +2,8 @@

{{ $bookmark->title }} @action('index') - # + # + e @endaction

{{ $bookmark->href }}

diff --git a/routes/web.php b/routes/web.php index 7cd0725..49788cd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -8,4 +8,6 @@ Route::get( return redirect()->action([BookmarkController::class, 'index']); } ); + Route::resource('bookmarks', BookmarkController::class); +Route::post('/bookmarks/{bookmark}', [BookmarkController::class, 'update']);