first commit

This commit is contained in:
dimon
2025-12-03 17:47:54 +00:00
commit 368ad0a220
100 changed files with 13791 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Models\Component;
use Illuminate\Http\Response;
class ComponentsController extends Controller
{
public function index(){
return response()->json(Component::all()->toJson());
}
public function show($id)
{
$component = Component::find($id);
if (!$component) {
return response()->json(['message' => 'Component not found'], 404);
}
return response()->json($component);
}
public function create(Request $request)
{
$name = $request->get(key:'name');
$type = $request->get(key:'type');
$brand = $request->get(key:'brand');
$model = $request->get(key:'model');
$price = $request->get(key:'price');
$component = new Component();
$component->name = $name;
$component->type = $type;
$component->brand = $brand;
$component->model = $model;
$component->price = $price;
$component->save();
return response()->json($component->toJson());
}
public function update(Request $request, int $id): JsonResponse{
return response()->json([
'name' => $request->get('name'),
'type' => $request->get('type'),
'brand' => $request->get('brand'),
'model' => $request->get('model'),
'price' => $request->get('price'),
], Response::HTTP_ACCEPTED);
}
public function destroy(int $id): JsonResponse
{
// мы бы здесь написали вызов запроса delete из БД
return response()->json([
'success' => true,
], Response::HTTP_ACCEPTED);
}
}