Skip to content

Commit

Permalink
add paper delete
Browse files Browse the repository at this point in the history
  • Loading branch information
eucyt committed Jun 22, 2023
1 parent 7ab40ba commit 3b6d142
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
9 changes: 6 additions & 3 deletions laravel/app/Http/Controllers/PaperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class PaperController extends Controller
{
Expand Down Expand Up @@ -84,10 +83,14 @@ public function update(UpdatePaperRequest $request, Paper $paper)
* Remove the specified resource from storage.
*
* @param Paper $paper
* @return Response
* @return RedirectResponse
*/
public function destroy(Paper $paper)
{
// TODO
if ($this->paper_service->delete($paper)) {
return redirect()->route('papers.index')->with('message', '削除しました。');
} else {
return redirect()->route('papers.index')->with('message', '削除できませんでした。');
}
}
}
10 changes: 10 additions & 0 deletions laravel/app/Services/PaperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,14 @@ private function normalizeTitle(string $title)
$title = preg_replace('/_+/', '_', $title);
return mb_strtolower($title);
}

/**
* delete the paper
* @param Paper $paper
* @return bool
*/
public function delete(Paper $paper)
{
return $paper->delete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('papers', function (Blueprint $table) {
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('papers', function (Blueprint $table) {
$this->dropColumn('deleted_at');
});
}
};
15 changes: 14 additions & 1 deletion laravel/resources/views/paper/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class="text-blue-700 hover:text-white border border-blue-700 hover:bg-blue-800 f
<th scope="col" class="w-1/3 py-3 px-6">
Memo
</th>
<th scope="col" class="w-1/6 py-3 px-6">
<th scope="col" class="w-1/12 py-3 px-6">
Author
</th>
<th scope="col" class="w-1/12 py-3 px-6">
Link
</th>
<th scope="col" class="w-1/12 py-3 px-6">
</th>
</tr>
</thead>
<tbody>
Expand All @@ -57,6 +59,17 @@ class="font-medium text-blue-600 dark:text-blue-500 hover:underline">{{ $paper->
<td class="py-4 px-6">
<a href={{ $paper->url }} target="_blank"
class="font-medium text-blue-600 dark:text-blue-500 hover:underline">Link
</a>
</td>
<td>
<form action="{{ route('papers.destroy', $paper->id) }}" method="POST">
@method('DELETE')
@csrf
<button type="submit"
class="text-red-700 hover:text-white border border-red-700 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-md text-sm px-2 py-1 text-center my-auto dark:border-red-500 dark:text-red-500 dark:hover:text-white dark:hover:bg-red-600 dark:focus:ring-red-800">
delete
</button>
</form>
</td>
</tr>
@endforeach
Expand Down

0 comments on commit 3b6d142

Please sign in to comment.