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.

143 lines
4.2 KiB

<?php
namespace App\Http\Controllers;
use App\Models\Peti;
use App\Models\Customer;
use Illuminate\Http\Request;
class RecycleDataController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$peti = Peti::onlyTrashed()->get();
$customer = Customer::onlyTrashed()->get();
$data = [
'peti' => Peti::onlyTrashed()->get(),
'customer' => Customer::onlyTrashed()->get(),
'active' => 'menu-Recycle_Data',
];
return view('dashboard.Master_Data.Recycle_Data.index', $data);
}
// public function pulihkanData($id)
// {
// // dd('oke');
// $peti = Customer::withTrashed()->find($id);
// if ($peti) {
// $peti->restore();
// return redirect()->back()->with('success', 'Data berhasil dipulihkan.');
// } else {
// return redirect()->back()->with('error', 'Data tidak ditemukan.');
// }
// }
// public function hapusPermanenData($id)
// {
// // dd('oke');
// $peti = Peti::withTrashed()->find($id);
// if ($peti) {
// $peti->forceDelete();
// return redirect()->back()->with('success', 'Data berhasil dihapus permanen.');
// } else {
// return redirect()->back()->with('error', 'Data tidak ditemukan.');
// }
// }
// public function pulihkanData(Request $request)
// {
// $peti = Peti::withTrashed()
// ->where('id', '=', $request->id)
// ->first();
// $customer = Customer::withTrashed()
// ->where('id', '=', $request->id)
// ->first();
// if ($peti) {
// $peti->restore();
// return redirect()->back()->with('success', 'Data Peti berhasil dipulihkan.');
// } elseif ($customer) {
// $customer->restore();
// return redirect()->back()->with('success', 'Data Customer berhasil dipulihkan.');
// } else {
// return redirect()->back()->with('error', 'Data tidak ditemukan.');
// }
// }
// public function hapusPermanenData($id)
// {
// $peti = Peti::withTrashed()->find($id);
// $customer = Customer::withTrashed()->find($id);
// if ($peti) {
// $peti->forceDelete();
// return redirect()->back()->with('success', 'Data Peti berhasil dihapus permanen.');
// } elseif ($customer) {
// $customer->forceDelete();
// return redirect()->back()->with('success', 'Data Customer berhasil dihapus permanen.');
// } else {
// return redirect()->back()->with('error', 'Data tidak ditemukan.');
// }
// }
public function pulihkanData(Request $request, $model, $id)
{
$data = null;
switch ($model) {
case 'peti':
$data = Peti::withTrashed()->find($id);
break;
case 'customer':
$data = Customer::withTrashed()->find($id);
break;
// Add more cases for other models if needed
default:
return redirect()->back()->with('error', 'Model tidak valid.');
}
if ($data) {
$data->restore();
return redirect()->back()->with('success', "Data $model berhasil dipulihkan.");
} else {
return redirect()->back()->with('error', 'Data tidak ditemukan.');
}
}
public function hapusPermanenData($model, $id)
{
$data = null;
switch ($model) {
case 'peti':
$data = Peti::withTrashed()->find($id);
break;
case 'customer':
$data = Customer::withTrashed()->find($id);
break;
// Add more cases for other models if needed
default:
return redirect()->back()->with('error', 'Model tidak valid.');
}
if ($data) {
$data->forceDelete();
return redirect()->back()->with('success', "Data $model berhasil dihapus permanen.");
} else {
return redirect()->back()->with('error', 'Data tidak ditemukan.');
}
}
}