abschlussprojekt-device-man.../device-app/app/Http/Controllers/DeviceController.php
2023-03-26 18:16:26 +02:00

73 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Device;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
class DeviceController extends Controller
{
//
public function index()
{
return view('devices.index', [
'devices' => Device::all()
]);
}
public function create(){
return view('devices.create');
}
public function store(Request $request){
$formFields = $request->validate([
'device_id' => ['required', Rule::unique('devices', 'device_id')],
'title' => 'required',
'device_type' => 'required',
'description' => 'required',
'accessories' => 'required',
'rz_username_buyer' => ['required', Rule::unique('devices', 'device_id')],
'serial_number' => 'required',
'image_url' => 'required',
]);
Device::create($formFields);
return redirect('/devices');
}
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', [
'device' => $device
]);
}
}