<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Ring;

class RingController extends Controller
{
    public function index()
    {
        $rings = Ring::all();
        return view('rings.index', compact('rings'));
    }

    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'image' => 'required|image|mimes:png,jpg,jpeg',
        ]);

        $path = $request->file('image')->store('rings', 'public');

        Ring::create([
            'name' => $request->name,
            'image_path' => $path,
        ]);

        return redirect()->back()->with('success', 'Ring added!');
    }

    public function getRingsApi()
    {
        return response()->json(Ring::all());
    }
}
