Add bookmark editing backend
This commit is contained in:
parent
1bbc1b9166
commit
f73c8310a1
@ -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
|
||||
|
@ -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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,25 +4,26 @@
|
||||
<p>
|
||||
<a href="{{ action('BookmarkController@index') }}">← Back</a>
|
||||
</p>
|
||||
<form action="post" class="form">
|
||||
<form method="post" class="form" action="{{ action('BookmarkController@update', ['bookmark' => $bookmark]) }}">
|
||||
@csrf
|
||||
<div class="bookmark">
|
||||
<div class="bookmark-title form-row">
|
||||
<div class="bookmark-title form-row"g>
|
||||
<label class="form-label" for="title">
|
||||
Title:
|
||||
</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 class="bookmark-href form-row form-row-stacked">
|
||||
<label class="form-label" for="href">
|
||||
URL:
|
||||
</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 class="bookmark-description form-row form-row-stacked">
|
||||
<label class="form-label" for="description">
|
||||
Description:
|
||||
</label>
|
||||
<textarea name="description" class="form-textarea">{{ htmlentities($bookmark->title) }}</textarea>
|
||||
<textarea name="description" class="form-textarea">{{ $bookmark->description }}</textarea>
|
||||
</div>
|
||||
<div class="form-row align-right bookmark-actions">
|
||||
<a class="form-button" href="{{ action('BookmarkController@show', ['bookmark' => $bookmark]) }}">Cancel</a>
|
||||
|
@ -2,7 +2,8 @@
|
||||
<p class="bookmark-title">
|
||||
{{ $bookmark->title }}
|
||||
@action('index')
|
||||
<a href="/bookmarks/{{ $bookmark->id }}">#</a>
|
||||
<a href="{{ action('BookmarkController@show', $bookmark) }}">#</a>
|
||||
<a href="{{ action('BookmarkController@edit', $bookmark) }}">e</a>
|
||||
@endaction
|
||||
</p>
|
||||
<p class="bookmark-href"><a href="{{ $bookmark->href }}">{{ $bookmark->href }}</a></p>
|
||||
|
@ -8,4 +8,6 @@ Route::get(
|
||||
return redirect()->action([BookmarkController::class, 'index']);
|
||||
}
|
||||
);
|
||||
|
||||
Route::resource('bookmarks', BookmarkController::class);
|
||||
Route::post('/bookmarks/{bookmark}', [BookmarkController::class, 'update']);
|
||||
|
Loading…
Reference in New Issue
Block a user