add update and delete
This commit is contained in:
parent
f39a0f9443
commit
13f933e0b5
@ -41,6 +41,28 @@ public function edit(Device $device) {
|
||||
return view('devices.edit', ['device' => $device]);
|
||||
}
|
||||
|
||||
public function update(Device $device, Request $request){
|
||||
$formFields = $request->validate([
|
||||
'device_id' => 'required',
|
||||
'title' => 'required',
|
||||
'device_type' => 'required',
|
||||
'description' => 'required',
|
||||
'accessories' => 'required',
|
||||
'rz_username_buyer' => 'required',
|
||||
'serial_number' => 'required',
|
||||
'image_url' => 'required',
|
||||
]);
|
||||
|
||||
$device->update($formFields);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
public function destroy(Device $device){
|
||||
$device->delete();
|
||||
return redirect('devices');
|
||||
}
|
||||
|
||||
public function show(Device $device)
|
||||
{
|
||||
return view('devices.show', [
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
@section('content')
|
||||
<form method="POST" action="/devices/{{$device->device_id}}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
@csrf
|
||||
<label for="device_id">device_id:</label>
|
||||
<input type="text" id="device_id" name="device_id" value="{{$device->device_id}}" required>
|
||||
@error('device_id')
|
||||
@ -47,7 +47,7 @@
|
||||
@enderror
|
||||
<br />
|
||||
<label for="description">description:</label>
|
||||
<textarea type="text" id="description" name="description">{{$device->rz_username_buyer}}</textarea>
|
||||
<textarea type="text" id="description" name="description">{{$device->description}}</textarea>
|
||||
@error('device_id')
|
||||
<p>{{$message}}</p>
|
||||
@enderror
|
||||
|
@ -13,4 +13,10 @@
|
||||
<li>{{ $device['image_url'] }}</li>
|
||||
</ul>
|
||||
<button><a href="{{$device->device_id}}/edit">Edit</a></button>
|
||||
|
||||
<form method="POST" action="{{$device->device_id}}">
|
||||
@method('DELETE')
|
||||
@csrf
|
||||
<button>Delete</button>
|
||||
</form>
|
||||
@endsection
|
||||
|
@ -32,6 +32,10 @@
|
||||
Route::get('devices/{device}/edit', [DeviceController::class, 'edit']);
|
||||
|
||||
// update - update device
|
||||
Route::put('devices/{device}', [DeviceController::class, 'update']);
|
||||
|
||||
// destroy - delete device
|
||||
Route::delete('devices/{device}', [DeviceController::class, 'destroy']);
|
||||
|
||||
// show - show sigle device
|
||||
Route::get('/devices/{device}', [DeviceController::class, 'show']);
|
||||
|
Loading…
Reference in New Issue
Block a user