Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 lines
2.3 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Requests\ValidasiCreateKondisiPeti;
use App\Http\Requests\ValidasiUpdateKondisiPeti;
use App\Models\Kondisi_Peti;
class KondisiPetiController extends Controller
{
public function index()
{
$data = [
'kondisiPeti' => Kondisi_Peti::orderBy('created_at', 'desc')->get(),
'active' => 'menu-kondisipeti'
];
return view('dashboard.Master_Data.Manajemen_Peti.Kondisi_Peti.index', $data);
}
public function store(ValidasiCreateKondisiPeti $request)
{
// dd('oke');
// dd($request);
try {
$currentUser = Auth::user();
$validatedData = $request->except('_token');
$validatedData['created_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai created_by
$validatedData['updated_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai updated_by
// dd($validatedData);
Kondisi_Peti::create($validatedData);
return redirect()->back()->with('success', 'Data Kondisi Peti Berhasil Ditambah.');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data Kondisi Peti Gagal Ditambah.');
}
}
public function update(ValidasiUpdateKondisiPeti $request, $id)
{
try {
$currentUser = Auth::user();
$kondisiPeti = Kondisi_Peti::findOrFail($id);
$validatedData = $request->except('_token');
$validatedData['updated_by'] = $currentUser->fullname;
$kondisiPeti->update($validatedData);
return redirect()->back()->with('success', 'Data Kondisi Peti Berhasil Diperbarui.');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data Kondisi Peti Gagal Diperbarui.');
}
}
public function destroy($id)
{
// dd("oke");
try {
$kondisiPeti = Kondisi_Peti::findOrFail($id);
$kondisiPeti->delete();
return redirect()->back()->with('success', 'Data kondisi peti berhasil dihapus');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data kondisi peti gagal dihapus');
}
}
}