102 lines
2.5 KiB
PHP
102 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class AdminSettingController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$settings = Setting::all();
|
|
return view('admin.setting.index', [
|
|
'settings' => $settings,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
// dd($request->persentase);
|
|
[$tahun, $bulan] = explode('-', $request->bulan_tahun);
|
|
Setting::create([
|
|
'bulan' => $bulan,
|
|
'tahun' => $tahun,
|
|
'persentase' => $request->persentase,
|
|
'status' => 'Active',
|
|
]);
|
|
return redirect()->route('admin-setting.index');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Setting $setting)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Setting $setting)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
// dd($setting['status'] );
|
|
$setting = Setting::findOrFail($id);
|
|
if ($setting->status == 'Active') {
|
|
$setting->status = 'Nonactive';
|
|
$result = $setting->save();
|
|
if ($result) {
|
|
return response()->json([
|
|
'message' => "Berhasil update kebijakan",
|
|
'status' => true,
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'message' => "Gagal update kebijakan",
|
|
'status' => true,
|
|
]);
|
|
}
|
|
} else {
|
|
$setting->status = 'Active';
|
|
$result = $setting->save();
|
|
if ($result) {
|
|
return response()->json([
|
|
'message' => "Berhasil update kebijakan",
|
|
'status' => true,
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'message' => "Gagal update kebijakan",
|
|
'status' => true,
|
|
]);
|
|
}
|
|
}
|
|
|
|
// return response()->json($id);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Setting $setting)
|
|
{
|
|
//
|
|
}
|
|
}
|