<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class AdminFashionDetailsController extends Controller
{
    public function index(Request $request)
    {
        $items = DB::table('product_items')->where('product_id',$request->id)->get();
        return view('admin/admin_fashion_details',
            [
                'items'=>$items,
                'name'=>$request->name,
                'product_id'=>$request->id,
                'title'=>'Fashion Details ',
            ]
        );
    }
    
    public function show(Request $request){
        $items = DB::table('product_items')->where('id',$request->id)->get();

        return response()->json([
            'success' => true,
            'message' => '',
            'data'    => $items[0]
        ]);
    }

    public function store(Request $request){
        $values = array(
            'product_id'=>$request->product_id,
            'quantity'=>$request->quantity,
            'price'=>$request->price,
            'size'=>$request->size,
            'weight'=>$request->weight,
        );

        $insertedId = DB::table('product_items')->insertGetId($values);
        
        $values['id'] = $insertedId;

        return response()->json([
            'success' => true,
            'message' => "Insert data berhasil!",
            'data' => $values,
        ]);
    }
    
    public function update(Request $request){
        $values = array(
            'id'=>$request->id,
            'quantity'=>$request->quantity,
            'price'=>$request->price,
            'size'=>$request->size,
            'weight'=>$request->weight,
        );

        DB::table('product_items')->where('id',$request->id)->update($values);

        return response()->json([
            'success' => true,
            'message' => 'Data Berhasil Diperbaharui',
            'data'    => $values,
        ]);
    }
    
    public function destroy(Request $request){
        DB::table('product_items')->where('id',$request->id)->delete();

        return response()->json([
            'success' => true,
            'message' => 'Hapus Data Berhasil',
            'data'    => $request->id
        ]);
    }

}

?>