-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
2,281 additions
and
31 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
app/Http/Controllers/Data/KategoriLembagaController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Data; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\KategoriLembagaRequest; | ||
use App\Models\KategoriLembaga; | ||
use Illuminate\Http\Request; | ||
use Yajra\DataTables\DataTables; | ||
|
||
class KategoriLembagaController extends Controller | ||
{ | ||
protected $title = 'Kategori Lembaga'; | ||
|
||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$page_title = $this->title; | ||
$page_description = 'Daftar ' . $this->title; | ||
$id_kecamatan = $this->profil->kecamatan_id; | ||
|
||
return view('data.lembaga_kategori.index', compact('page_title', 'page_description', 'id_kecamatan')); | ||
} | ||
|
||
public function getData(Request $request) | ||
{ | ||
if ($request->ajax()) { | ||
$kategoris = KategoriLembaga::withCount('lembaga')->get(); | ||
return DataTables::of($kategoris) | ||
->addIndexColumn() | ||
->addColumn('aksi', function ($row) { | ||
if (! auth()->guest()) { | ||
$data['edit_url'] = route('data.kategori-lembaga.edit', $row->id); | ||
$data['delete_url'] = route('data.kategori-lembaga.destroy', $row->id); | ||
} | ||
|
||
return view('forms.aksi', $data); | ||
}) | ||
->editColumn('deskripsi', function ($row) { | ||
return $row->deskripsi ? $row->deskripsi : '-'; | ||
}) | ||
->rawColumns(['deskripsi']) | ||
->make(true); | ||
} | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
$page_title = $this->title; | ||
$page_description = 'Tambah ' . $this->title; | ||
|
||
return view('data.lembaga_kategori.create', compact('page_title', 'page_description')); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(KategoriLembagaRequest $request) | ||
{ | ||
try { | ||
KategoriLembaga::create($request->all()); | ||
} catch (\Exception $e) { | ||
report($e); | ||
|
||
return back()->withInput()->with('error', 'Kategori Lembaga gagal ditambah!'); | ||
} | ||
|
||
return redirect()->route('data.kategori-lembaga.index')->with('success', 'Kategori Lembaga berhasil ditambah!'); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit($id) | ||
{ | ||
$kategori_lembaga = KategoriLembaga::findOrFail($id); | ||
$page_title = $this->title; | ||
$page_description = 'Ubah '. $this->title; | ||
|
||
return view('data.lembaga_kategori.edit', compact('page_title', 'page_description', 'kategori_lembaga')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(KategoriLembagaRequest $request, $id) | ||
{ | ||
try { | ||
KategoriLembaga::findOrFail($id)->update($request->all()); | ||
} catch (\Exception $e) { | ||
report($e); | ||
|
||
return back()->withInput()->with('error', 'Kategori Lembaga gagal diubah!'); | ||
} | ||
|
||
return redirect()->route('data.kategori-lembaga.index')->with('success', 'Kategori Lembaga berhasil diubah!'); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
try { | ||
KategoriLembaga::findOrFail($id)->delete(); | ||
} catch (\Exception $e) { | ||
report($e); | ||
|
||
return redirect()->route('data.kategori-lembaga.index')->with('error', 'Kategori Lembaga gagal dihapus!'); | ||
} | ||
|
||
return redirect()->route('data.kategori-lembaga.index')->with('success', 'Kategori Lembaga berhasil dihapus!'); | ||
} | ||
} |
Oops, something went wrong.