Skip to content

Commit

Permalink
W końcu chyba działa
Browse files Browse the repository at this point in the history
  • Loading branch information
Prawy126 committed Jun 4, 2024
1 parent 742aef4 commit dd88128
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
5 changes: 2 additions & 3 deletions Projekt/app/Http/Controllers/AnnouncementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function edit($id)

public function update(Request $request, $id)
{
dd($request);
$request->validate([
'name' => 'required|string|max:30',
'brand' => 'required|string|max:30',
Expand Down Expand Up @@ -146,7 +145,7 @@ public function update(Request $request, $id)
return redirect()->route('cars.show', $announcement->id)->with('error', 'Nie można zaktualizować zakończonej aukcji.');
}

$announcement->update($request->all());
$announcement->update($request->only(['name', 'brand', 'year', 'mileage', 'description', 'min_price', 'end_date', 'end_date']));

if ($request->hasFile('images')) {
foreach ($request->file('images') as $image) {
Expand All @@ -159,9 +158,9 @@ public function update(Request $request, $id)
}
}


return redirect()->route('cars.show', $announcement->id)->with('success', 'Ogłoszenie zostało zaktualizowane.');
}

public function create()
{
return view('announcements.create');
Expand Down
47 changes: 40 additions & 7 deletions Projekt/resources/views/cars/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,84 @@
</div>
@endif

<form action="{{ route('announcements.update', $announcement->id) }}" method="POST">
<form action="{{ route('announcements.update', $announcement->id) }}" method="POST"
enctype="multipart/form-data">
@csrf
@method('PUT')

<div class="mb-3">
<label for="name" class="form-label">Marka</label>
<input type="text" class="form-control" id="name" name="name" value="{{ old('name', $announcement->name) }}" required>
<input type="text" class="form-control" id="name" name="name"
value="{{ old('name', $announcement->name) }}" required>
</div>

<div class="mb-3">
<label for="brand" class="form-label">Model</label>
<input type="text" class="form-control" id="brand" name="brand" value="{{ old('brand', $announcement->brand) }}" required>
<input type="text" class="form-control" id="brand" name="brand"
value="{{ old('brand', $announcement->brand) }}" required>
</div>

<div class="mb-3">
<label for="year" class="form-label">Rok produkcji</label>
<input type="number" class="form-control" id="year" name="year" value="{{ old('year', $announcement->year) }}" required>
<input type="number" class="form-control" id="year" name="year"
value="{{ old('year', $announcement->year) }}" required>
</div>

<div class="mb-3">
<label for="mileage" class="form-label">Przebieg</label>
<input type="number" class="form-control" id="mileage" name="mileage" value="{{ old('mileage', $announcement->mileage) }}" required>
<input type="number" class="form-control" id="mileage" name="mileage"
value="{{ old('mileage', $announcement->mileage) }}" required>
</div>

<div class="mb-3">
<label for="min_price" class="form-label">Cena</label>
<input type="number" class="form-control" id="price" name="min_price" value="{{ old('min_price', $announcement->min_price) }}" required>
<input type="number" class="form-control" id="min_price" name="min_price"
value="{{ old('min_price', $announcement->min_price) }}" required>
</div>

<div class="mb-3">
<label for="description" class="form-label">Opis</label>
<textarea class="form-control" id="description" name="description" rows="5" required>{{ old('description', $announcement->description) }}</textarea>
</div>

<div class="mb-3">
<label for="end_date" class="form-label">Data końcowa</label>
<input type="datetime-local" class="form-control" id="end_date" name="end_date" value="{{$date}}" >
<input type="datetime-local" class="form-control" id="end_date" name="end_date"
value="{{ old('end_date', \Carbon\Carbon::parse($announcement->end_date)->format('Y-m-d\TH:i')) }}"
required>
</div>

<div class="mb-3">
<label for="carImages" class="form-label">Zdjęcia</label>
<input type="file" class="form-control" id="carImages" name="images[]" multiple>
</div>



<button type="submit" class="btn btn-success">Zapisz zmiany</button>
<a href="{{ route('cars.index') }}" class="btn btn-secondary">Anuluj</a>
<div class="container mt-5">
<div class='row'>
</form>
<h4>Aktualne zdjęcia</h4>
@foreach ($announcement->photos as $photo)
<div class="col-md-3">
<img src="{{ asset('storage/' . $photo->photo_name) }}" class="img-fluid mb-2">
<form action="{{ route('photos.destroy', $photo->id) }}" method="POST">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger btn-sm">Usuń</button>
</form>
</div>
@endforeach
<div class="container mt-5">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@include('shared.footer', ['fixedBottom' => true])
</body>

0 comments on commit dd88128

Please sign in to comment.