showing a delete button if a post is visited by its owner

This commit is contained in:
Ghostie 2024-08-22 19:03:29 -05:00
parent 75ebb57dd3
commit c23d029890
3 changed files with 15 additions and 0 deletions

View File

@ -57,4 +57,9 @@ class PostController extends Controller implements HasMiddleware
"user" => $user
]);
}
public function destroy(Post $post)
{
dd("Deleting ", $post->id);
}
}

View File

@ -22,6 +22,15 @@
{{ $post->description }}
</p>
</div>
@auth
@if ($post->user_id === auth()->user()->id)
<form action="#">
<input type="submit" value="Delete post"
class="bg-red-500 hover:bg-red-600 p-2 rounded text-white font-bold mt-4 cursor-pointer">
</form>
@endif
@endauth
</div>
<div class="md:w-1/2 p-5">

View File

@ -24,6 +24,7 @@ Route::get("/{user:username}", [PostController::class, "index"])->name("posts.in
Route::get("/posts/create", [PostController::class, "create"])->name("posts.create");
Route::post("/posts", [PostController::class, "store"])->name("posts.store");
Route::get("/{user:username}/posts/{post}", [PostController::class, "show"])->name("posts.show");
Route::delete("/posts/{post}", [PostController::class, "destroy"])->name("posts.destroy");
Route::post("/{user:username}/posts/{post}", [CommentController::class, "store"])->name("comment.store");