abschlussprojekt-device-man.../device-app/app/Http/Controllers/DeviceController.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2023-03-25 11:02:47 +01:00
<?php
namespace App\Http\Controllers;
use App\Models\Device;
use Illuminate\Http\Request;
2023-03-26 12:17:43 +02:00
use Illuminate\Validation\Rule;
2023-03-25 11:02:47 +01:00
class DeviceController extends Controller
{
//
public function index()
{
return view('devices.index', [
'devices' => Device::all()
]);
}
2023-03-26 11:32:54 +02:00
public function create(){
2023-03-26 12:17:43 +02:00
return view('devices.create');
}
2023-03-26 11:32:54 +02:00
2023-03-26 12:17:43 +02:00
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',
2023-03-26 11:32:54 +02:00
]);
2023-03-26 12:17:43 +02:00
Device::create($formFields);
return redirect('/devices');
2023-03-26 11:32:54 +02:00
}
2023-03-25 11:02:47 +01:00
public function show(Device $device)
{
return view('devices.show', [
'device' => $device
]);
}
}