<?php

namespace App\Http\Controllers;

use App\Models\Subcategory;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Item;
use Illuminate\Support\Facades\DB;

class RegisterItemController extends Controller
{
    public function jsonSubcategoryRequest(Request $request)
    {

        $requestData = $request->all();
        $action = isset($requestData['action']) ? $requestData['action'] : '';

        if ($action == 'getSubcategory') {

            $subcategory = Subcategory::where('category_id', '=', $requestData['category'])->get();
            return $subcategory;
            if ($subcategory) {

                return json_encode($subcategory);
            } else {
                return json_encode($request->all());
                return json_encode('Выберите категорию');
            }

        }
        return json_encode($request->all());

    }
}
