From a707aadd4f7c32dcbd65c07dffc5df6156240d5f Mon Sep 17 00:00:00 2001 From: Stefan Zwischenbrugger Date: Mon, 30 Mar 2026 10:36:09 +0200 Subject: [PATCH] Listen: anlegen, Titel, Foto-Log Made-with: Cursor --- .../Controllers/ShoppingListController.php | 4 -- .../ShoppingListCreateController.php | 32 +++++++++++++++ .../Requests/StoreShoppingListRequest.php | 39 +++++++++++++++++++ resources/views/shopping-list/index.blade.php | 20 +++++++++- .../partials/item-pencil-panel.blade.php | 3 +- routes/web.php | 2 + 6 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 app/Http/Controllers/ShoppingListCreateController.php create mode 100644 app/Http/Requests/StoreShoppingListRequest.php diff --git a/app/Http/Controllers/ShoppingListController.php b/app/Http/Controllers/ShoppingListController.php index a7641c9..f3ccd97 100644 --- a/app/Http/Controllers/ShoppingListController.php +++ b/app/Http/Controllers/ShoppingListController.php @@ -109,10 +109,6 @@ class ShoppingListController extends Controller 'done_at' => $isDone ? Carbon::now() : null, ]); - if (! $isDone) { - return; - } - $photoPath = $request->file('photo')?->store('price-photos', 'public'); if (! $request->filled('price_decimal') && $photoPath === null) { diff --git a/app/Http/Controllers/ShoppingListCreateController.php b/app/Http/Controllers/ShoppingListCreateController.php new file mode 100644 index 0000000..40d75bc --- /dev/null +++ b/app/Http/Controllers/ShoppingListCreateController.php @@ -0,0 +1,32 @@ +user(); + + $list = DB::transaction(function () use ($request, $user): ShoppingList { + $list = ShoppingList::query()->create([ + 'owner_id' => $user->id, + 'name' => $request->string('name')->toString(), + ]); + $list->members()->attach($user->id); + + return $list; + }); + + $request->session()->put('current_shopping_list_id', $list->id); + + return redirect()->route('dashboard')->with('status', 'Liste wurde erstellt.'); + } +} + diff --git a/app/Http/Requests/StoreShoppingListRequest.php b/app/Http/Requests/StoreShoppingListRequest.php new file mode 100644 index 0000000..80bbaf4 --- /dev/null +++ b/app/Http/Requests/StoreShoppingListRequest.php @@ -0,0 +1,39 @@ +user() !== null; + } + + /** + * @return array|string> + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + ]; + } + + public function messages(): array + { + return [ + 'name.required' => 'Bitte gib einen Listennamen ein.', + 'name.max' => 'Der Listenname darf maximal 255 Zeichen lang sein.', + ]; + } + + public function attributes(): array + { + return [ + 'name' => 'Listenname', + ]; + } +} + diff --git a/resources/views/shopping-list/index.blade.php b/resources/views/shopping-list/index.blade.php index 20084b2..ef4ebe4 100644 --- a/resources/views/shopping-list/index.blade.php +++ b/resources/views/shopping-list/index.blade.php @@ -1,7 +1,7 @@

- Einkaufsliste + {{ $currentList->name }}

@@ -195,6 +195,22 @@ (geteilt von {{ $currentList->owner->name }}) @endif

+
+ @csrf + + + +
@if($accessibleLists->count() > 1)
@csrf @@ -202,7 +218,7 @@ -

Preis und Foto werden nur gespeichert, wenn der Eintrag als erledigt markiert ist.

+

Preis und Foto koennen auch ohne „erledigt“ gespeichert werden.

group(function () { Route::patch('/shopping-items/{shoppingItem}', [ShoppingListController::class, 'update'])->name('shopping-items.update'); Route::patch('/shopping-items/{shoppingItem}/toggle', [ShoppingListController::class, 'toggle'])->name('shopping-items.toggle'); + Route::post('/shopping-lists', ShoppingListCreateController::class)->name('shopping-lists.store'); Route::post('/shopping-lists/{shoppingList}/switch', ShoppingListSwitchController::class)->name('shopping-lists.switch'); Route::post('/shopping-lists/{shoppingList}/members', [ShoppingListMemberController::class, 'store'])->name('shopping-lists.members.store'); Route::delete('/shopping-lists/{shoppingList}/members/{user}', [ShoppingListMemberController::class, 'destroy'])->name('shopping-lists.members.destroy');