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.

76 lines
2.6 KiB

1 year ago
<?php
namespace App\Http\Controllers;
1 year ago
use App\Models\Kondisi_Peti;
1 year ago
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
1 year ago
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Requests\ValidasiCreateKondisiPeti;
use App\Http\Requests\ValidasiUpdateKondisiPeti;
1 year ago
use App\Imports\KondisiPetiImport;
1 year ago
class KondisiPetiController extends Controller
{
public function index()
{
$data = [
'kondisiPeti' => Kondisi_Peti::orderBy('created_at', 'desc')->get(),
1 year ago
'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');
}
}
1 year ago
public function importKondisiPeti(Request $request)
{
Excel::import(new KondisiPetiImport, request()->file('file'));
return redirect()->route('dashboard.kondisipeti.index')->with('success', 'Data kondisi peti berhasil di import');
}
1 year ago
}