sibanu_web/app/Http/Controllers/DivisiController.php
2022-08-20 13:21:23 +07:00

86 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Divisi;
use Illuminate\Support\Facades\DB;
class DivisiController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\View\View
*/
public function index()
{
$data['menu'] = 'Manajemen Pengguna';
$data['current_page'] = 'data-divisi';
$data['divisi'] = Divisi::all();
return view('admin.divisi.index',$data);
}
public function update_ajax(Request $request){
$data_update = array(
'nama_divisi' => $request->nama_divisi
);
$id = $request->id;
$update = DB::table('tbl_divisi')->where('id',$id)->update($data_update);
if($update){
return redirect('divisi')->with('sukses','Data Divisi Berhasil di update ...');
}else{
return redirect('divisi')->with('error','Data Divisi Gagal di update ....');
}
}
public function hapus($id){
$hapus = DB::table('tbl_divisi')->where('id',$id)->delete();
if($hapus){
return redirect('divisi')->with('sukses','Data Divisi Berhasil di hapus ...');
}else{
return redirect('divisi')->with('error','Data Divisi Gagal di hapus ....');
}
}
public function store(Request $request){
$data = array(
'nama_divisi' => $request->nama_divisi
);
$insert = DB::table('tbl_divisi')->insert($data);
if($insert){
return redirect('divisi')->with('sukses', 'Data Divisi Berhasil di tambahkan ..');
}else{
return redirect('divisi')->with('error', 'Data Divisi Gagal di tambahkan ..');
}
}
}