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.
78 lines
2.1 KiB
78 lines
2.1 KiB
12 months ago
|
<?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(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.');
|
||
|
}
|
||
|
}
|
||
|
}
|