mirror of https://github.com/kcal-app/kcal.git
				
				
				
			Add recipe delete functionality
This commit is contained in:
		
							parent
							
								
									465c466a93
								
							
						
					
					
						commit
						d3a881c359
					
				|  | @ -254,4 +254,26 @@ class RecipeController extends Controller | ||||||
|         return redirect()->route('recipes.show', $recipe); |         return redirect()->route('recipes.show', $recipe); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Confirm removal of specified resource. | ||||||
|  |      */ | ||||||
|  |     public function delete(Recipe $recipe): View | ||||||
|  |     { | ||||||
|  |         return view('recipes.delete')->with('recipe', $recipe); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Remove the specified resource from storage. | ||||||
|  |      */ | ||||||
|  |     public function destroy(Recipe $recipe): RedirectResponse | ||||||
|  |     { | ||||||
|  |         // Remove the recipe from any recipes.
 | ||||||
|  |         foreach ($recipe->ingredientAmountRelationships as $ia) { | ||||||
|  |             $ia->delete(); | ||||||
|  |         } | ||||||
|  |         $recipe->delete(); | ||||||
|  |         return redirect(route('recipes.index')) | ||||||
|  |             ->with('message', "Recipe {$recipe->name} deleted!"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,46 @@ | ||||||
|  | <x-app-layout> | ||||||
|  |     <x-slot name="header"> | ||||||
|  |         <h2 class="font-semibold text-xl text-gray-800 leading-tight"> | ||||||
|  |             Delete {{ $recipe->name }}? | ||||||
|  |         </h2> | ||||||
|  |     </x-slot> | ||||||
|  | 
 | ||||||
|  |     <div class="py-12"> | ||||||
|  |         <div class="max-w-7xl mx-auto sm:px-6 lg:px-8"> | ||||||
|  |             <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg"> | ||||||
|  |                 <div class="p-6 bg-white border-b border-gray-200"> | ||||||
|  |                     <form method="POST" action="{{ route('recipes.destroy', $recipe) }}"> | ||||||
|  |                         @method('delete') | ||||||
|  |                         @csrf | ||||||
|  |                         <div class="pb-3"> | ||||||
|  |                             <div class="text-lg">Are you sure what to delete <span class="font-extrabold">{{ $recipe->name }}</span>?</div> | ||||||
|  |                             <div class="flex flex-col space-y-2 mt-2 text-lg"> | ||||||
|  |                                 @if(!$recipe->ingredientAmountRelationships->isEmpty()) | ||||||
|  |                                     <div class="flex space-x-2 items-center text-lg"> | ||||||
|  |                                         <div class="text-yellow-500"> | ||||||
|  |                                             <svg class="h-8 w-8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"> | ||||||
|  |                                                 <path fill-rule="evenodd" d="M10 1.944A11.954 11.954 0 012.166 5C2.056 5.649 2 6.319 2 7c0 5.225 3.34 9.67 8 11.317C14.66 16.67 18 12.225 18 7c0-.682-.057-1.35-.166-2.001A11.954 11.954 0 0110 1.944zM11 14a1 1 0 11-2 0 1 1 0 012 0zm0-7a1 1 0 10-2 0v3a1 1 0 102 0V7z" clip-rule="evenodd" /> | ||||||
|  |                                             </svg> | ||||||
|  |                                         </div> | ||||||
|  |                                         <div>Deleting this recipe will also remove it from the following recipes:</div> | ||||||
|  |                                     </div> | ||||||
|  |                                     <ul class="list-disc list-inside ml-3 space-y-1"> | ||||||
|  |                                         @foreach ($recipe->ingredientAmountRelationships as $ia) | ||||||
|  |                                             <li> <a class="text-gray-500 hover:text-gray-700" | ||||||
|  |                                                     href="{{ route('recipes.show', $ia->parent) }}">{{ $ia->parent->name }}</a></li> | ||||||
|  |                                         @endforeach | ||||||
|  |                                     </ul> | ||||||
|  |                                 @endif | ||||||
|  |                             </div> | ||||||
|  |                         </div> | ||||||
|  |                         <x-inputs.button class="bg-red-800 hover:bg-red-700"> | ||||||
|  |                             Yes, delete | ||||||
|  |                         </x-inputs.button> | ||||||
|  |                         <a class="ml-3 text-gray-500 hover:text-gray-700" href="{{ route('recipes.show', $recipe) }}"> | ||||||
|  |                             No, do not delete</a> | ||||||
|  |                     </form> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </x-app-layout> | ||||||
|  | @ -9,6 +9,12 @@ | ||||||
|                     <path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd" /> |                     <path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd" /> | ||||||
|                 </svg> |                 </svg> | ||||||
|             </a> |             </a> | ||||||
|  |             <a class="h-6 w-6 text-red-500 hover:text-red-700 hover:border-red-300 float-right text-sm" | ||||||
|  |                href="{{ route('recipes.delete', $recipe) }}"> | ||||||
|  |                 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"> | ||||||
|  |                     <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" /> | ||||||
|  |                 </svg> | ||||||
|  |             </a> | ||||||
|         </h2> |         </h2> | ||||||
|     </x-slot> |     </x-slot> | ||||||
|     <div class="py-12"> |     <div class="py-12"> | ||||||
|  |  | ||||||
|  | @ -43,5 +43,6 @@ Route::get('/journal-entries/{journalEntry}/delete', [JournalEntryController::cl | ||||||
| 
 | 
 | ||||||
| // Recipes.
 | // Recipes.
 | ||||||
| Route::resource('recipes', RecipeController::class)->middleware(['auth']); | Route::resource('recipes', RecipeController::class)->middleware(['auth']); | ||||||
|  | Route::get('/recipes/{recipe}/delete', [RecipeController::class, 'delete'])->middleware(['auth'])->name('recipes.delete'); | ||||||
| 
 | 
 | ||||||
| require __DIR__.'/auth.php'; | require __DIR__.'/auth.php'; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue