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.

118 lines
3.6 KiB

1 year ago
<?php
namespace App\Http\Controllers;
1 year ago
use App\Models\asset_status;
use App\Models\m_asset;
use App\Models\m_warehouse;
1 year ago
use Illuminate\Http\Request;
1 year ago
use Illuminate\Support\Facades\Auth;
1 year ago
class PeminjamanController extends Controller
{
1 year ago
/**
* Display a listing of the resource.
*/
1 year ago
public function index()
{
1 year ago
$asset = m_asset::all();
$peminjaman = asset_status::get();
$warehouse = m_warehouse::get();
return view('dashboard.Peminjaman.index', compact('asset', 'peminjaman', 'warehouse'));
1 year ago
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$asset = m_asset::all();
$peminjaman = asset_status::get();
$warehouse = m_warehouse::get();
return view('dashboard.Peminjaman.create', compact('asset', 'peminjaman', 'warehouse'));
1 year ago
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd('oke');
$request->validate([
'asset_id' => 'required',
'exit_at' => 'required',
'exit_pic' => 'required',
'exit_warehouse' => 'required',
]);
// dd($request);
try {
$currentUser = Auth::user();
$validatedData = $request->except('_token');
$validatedData['created_by'] = $currentUser->id; // Menambahkan ID pengguna sebagai created_by
$validatedData['updated_by'] = $currentUser->id; // Menambahkan ID pengguna sebagai updated_by
// dd($validatedData);
asset_status::create($validatedData);
return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil ditambah.');
1 year ago
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data peminjaman gagal ditambah.');
}
}
/**
* Display the specified resource.
*/
public function show($id)
{
// dd('oke');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
1 year ago
{
$peminjaman = asset_status::find($id);
$asset = m_asset::all();
$warehouse = m_warehouse::get();
return view('dashboard.Peminjaman.edit', compact('asset', 'peminjaman', 'warehouse'));
1 year ago
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
// dd('oke');
$request->validate([
'asset_id' => 'required',
'exit_at' => 'required',
'exit_pic' => 'required',
'exit_warehouse' => 'required',
]);
// dd($request);
try {
$peminjaman = asset_status::findOrFail($id);
$peminjaman['updated_by'] = Auth::user()->fullname; // Menambahkan ID pengguna sebagai updated_by
1 year ago
$peminjaman->update($request->all());
return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil diperbaharui');
1 year ago
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data peminjaman gagal diperbaharui');
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$peminjaman = asset_status::findOrFail($id);
$peminjaman->delete();
return redirect()->back()->with('success', 'Data peminjaman berhasil dihapus');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data peminjaman gagal dihapus');
}
1 year ago
}
}