Edit paddock name and state.

TODO: keep track of paddock openings.
This commit is contained in:
2020-04-17 09:57:10 +02:00
parent 19e1123ef5
commit 6a57222caf
3 changed files with 60 additions and 4 deletions

View File

@@ -67,7 +67,9 @@ class PaddockController extends Controller
*/
public function edit($id)
{
//
$data['paddock'] = Paddock::where('id', $id)->first();
return view('paddock.edit', $data);
}
/**
@@ -79,7 +81,18 @@ class PaddockController extends Controller
*/
public function update(Request $request, $id)
{
//
$request->validate([
'name' => 'required',
]);
$update = [
'name' => $request->name,
'isClosed' => $request->state !== 'opened',
];
Paddock::where('id', $id)->update($update);
return Redirect::to('paddocks')
->with('success', 'Enclos mis à jour.');
}
/**

View File

@@ -0,0 +1,40 @@
@extends('paddock.layout')
@section('content')
<h2>Édition d'un enclos</h2>
<br>
<form action="{{ route('paddocks.update', $paddock->id) }}" method="POST">
{{ csrf_field() }}
@method('PATCH')
<strong>Nom</strong>
<input type="text"
name="name"
value="{{ $paddock->name }}">
<span class="text-danger">{{ $errors->first('name') }}</span>
<!-- Paddock status -->
<fielset>
<strong>Statut</strong>
<input type="radio"
name="state"
value="opened"
id="paddock-state-opened"
{{ $paddock->isClosed ? '' : 'checked' }}>
<label for="paddock-state-opened">Ouvert</label>
<input type="radio"
name="state"
value="closed"
id="paddock-state-closed"
{{ $paddock->isClosed ? 'checked' : '' }}>
<label for="paddock-state-closed">Fermé</label>
</fieldset>
<button type="submit">Mettre à jour</button>
</form>
@endsection

View File

@@ -14,7 +14,7 @@
<th>Id</th>
<th>Nom</th>
<th>État</th>
<th>Actions</th>
<th colspan="2">Actions</th>
</thead>
<tbody>
@foreach($paddocks as $paddock)
@@ -22,6 +22,9 @@
<td>{{ $paddock->id }}</td>
<td>{{ $paddock->name }}</td>
<td>{{ $paddock->isClosed ? 'Fermé' : 'Ouvert' }}</td>
<td>
<a href="{{ route('paddocks.edit', $paddock->id)}}">Éditer</a>
</td>
<td>
<form action="{{ route('paddocks.destroy', $paddock->id)}}" method="post">
{{ csrf_field() }}