Anons79 Mini Shell

Directory : /home/aplikasiposinfo/www/langganan.fixmate.id/app/Http/Controllers/
Upload File :
Current File : /home/aplikasiposinfo/www/langganan.fixmate.id/app/Http/Controllers/DetailPaketController.php

<?php

namespace App\Http\Controllers;

use App\Models\detailPaket;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use PDO;
use Throwable;

class DetailPaketController extends Controller
{

    public function getDetail(String $id)
    {
        $itemPaket = detailPaket::where('paket_id', $id)->with(['paket', 'item'])->latest()->get();
        return response()->json(
            [
                'status' => 'success',
                'data' => $itemPaket,
            ]
        );
    }
    public function store(Request $request)
    {
        try {
            $detail = detailPaket::where('paket_id', $request->paket_id)->where('item_id', $request->item_id)->count();
            if ($detail == 0) {
                $data = [
                    'paket_id' => $request->paket_id,
                    'item_id' => $request->item_id,
                ];

                detailPaket::create($data);
                return response()->json([
                    'status' => 'success',
                    'message' => 'Data Detail Paket Berhasil Ditambahkan!.',
                ], 200);
            } else {
                return response()->json([
                    'status' => 'error',
                    'error' => 'detail telah Tersedia',
                ], 422);
            }
        } catch (Throwable $th) {
            return response()->json([
                'status' => 'error',
                'error' => $th->getMessage(),

            ], 422);
        }
    }
    public function destroy(String $id)
    {
        try {
            $item = detailPaket::find($id);
            $item->delete();

            return response()->json([
                'status' => 'success',
                'message' => 'Data berhasil dihapus!',
            ], 200);
        } catch (Throwable $th) {
            return response()->json([
                'status' => 'error',
                'message' => 'Terjadi kesalahan: ' . $th->getMessage(),
            ], 500);
        }
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]