<?php

namespace App\Http\Controllers;

use App\SettingSupplier;
use Illuminate\Http\Request;

class SettingSupplierController extends Controller
{
    public function index()
    {
        $suppliers = SettingSupplier::all();

        foreach ($suppliers as $supplier) {
            $supplier->value = $supplier->id;
            $supplier->label = $supplier->company_name;
        }
        return $suppliers;
    }

    public function show(SettingSupplier $supplier)
    {
        return $supplier;
    }

    public function store(Request $request)
    {
        $supplier = SettingSupplier::create($request->all());

        return response()->json($supplier, 201);
    }

    public function update(Request $request, SettingSupplier $supplier)
    {
        $supplier->update($request->all());

        return response()->json($supplier, 200);
    }

    public function delete(SettingSupplier $supplier)
    {
        $supplier->delete();

        return response()->json(null, 204);
    }
}