61 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
<?php
 | 
						|
 | 
						|
namespace App\Http\Controllers;
 | 
						|
 | 
						|
use App\Http\Requests\SubKategoriRequest;
 | 
						|
use App\Models\Kategori;
 | 
						|
use App\Models\SubKategori;
 | 
						|
use Illuminate\Http\Request;
 | 
						|
use Illuminate\Support\Facades\Log;
 | 
						|
use Inertia\Inertia;
 | 
						|
 | 
						|
class SubKategoriController extends Controller
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Display a listing of the resource.
 | 
						|
     */
 | 
						|
    public function index()
 | 
						|
    {
 | 
						|
        $subkategori = SubKategori::with('kategori')->latest()->get();
 | 
						|
        $kategori = Kategori::all();
 | 
						|
 | 
						|
        return Inertia::render('admin/subkategori/index_subkategori', [
 | 
						|
            'subkategori' => $subkategori,
 | 
						|
            'kategori' => $kategori
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
 | 
						|
    public function store(SubKategoriRequest $request)
 | 
						|
    {
 | 
						|
        try {
 | 
						|
            SubKategori::create($request->validated());
 | 
						|
            return redirect()->route('admin.subkategori.index')->with('success', 'SubKategori berhasil dibuat.');
 | 
						|
        } catch (\Exception $e) {
 | 
						|
            Log::error('Error creating SubKategori: ' . $e->getMessage());
 | 
						|
            return back()->with('error', 'Something went wrong.');
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public function update(SubKategoriRequest $request, SubKategori $subkategori)
 | 
						|
    {
 | 
						|
        try {
 | 
						|
            $subkategori->update($request->validated());
 | 
						|
            return redirect()->route('admin.subkategori.index')->with('success', 'SubKategori berhasil diperbarui.');
 | 
						|
        } catch (\Exception $e) {
 | 
						|
            Log::error('Error updating SubKategori: ' . $e->getMessage());
 | 
						|
            return back()->with('error', 'Something went wrong.');
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public function destroy(SubKategori $subkategori)
 | 
						|
    {
 | 
						|
        try {
 | 
						|
            $subkategori->delete();
 | 
						|
            return redirect()->route('admin.subkategori.index')->with('success', 'SubKategori berhasil dihapus.');
 | 
						|
        } catch (\Exception $e) {
 | 
						|
            Log::error('Error deleting SubKategori: ' . $e->getMessage());
 | 
						|
            return back()->with('error', 'Something went wrong.');
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |