Skip to content

Commit

Permalink
delete button implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
alaminkawsar committed Jul 10, 2023
1 parent 564f432 commit 1e9d574
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function update(Request $request, Book $book)
*/
public function destroy(Book $book)
{
//
$book->delete();
return redirect()->route('books.index')->with('success','Deleted Successfully');
}
}
14 changes: 9 additions & 5 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<th scope="col">Action</th>
</tr>
</thead>
<tbody class="text-center">
<tbody>
@foreach($books as $book)
<tr>
<th scope="row">{{$book->id}}</th>
Expand All @@ -32,12 +32,16 @@
<td>{{$book->isbn}}</td>
<td>{{$book->price}}</td>
<td>{{$book->available}}</td>
<td>
<div class="mx-auto">
<td class="d-flex">
<div class="d-flex gap-3">
<a href="{{route('books.show',$book->id)}}" class="btn btn-secondary">View</a>
<a href="{{route('books.edit',$book->id)}}" class="btn btn-primary">Edit</a>
<button type="button" class="btn btn-danger">Danger</button>
</div>
<form action = "{{route('books.destroy',$book->id)}}" method="post">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Danger</button>
</form>
</div>
</td>
</tr>
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion resources/views/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@section('content')

<div class="card" style="width: 50rem;">
<div class="card col-md-3 mx-auto">
<div class="card-body">
<h1 class="card-title text-center">Book Information</h1>
<div class="card">
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
Route::get('/books/{book}/show',[BookController::class,'show'])->name('books.show');
Route::get('books/{book}/edit',[BookController::class,'edit'])->name('books.edit');
Route::patch('/books/{book}/update',[BookController::class,'update'])->name('books.update');
Route::delete('/books/{book}/destroy',[BookController::class,'destroy'])->name('books.destroy');

0 comments on commit 1e9d574

Please sign in to comment.