123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- <?php
-
- namespace {{ namespace }};
-
- use {{ rootNamespace }}Http\Controllers\Controller;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Http\Request;
- use App\Helpers\Helper;
- use Validator;
- use Hashids;
- use Yajra\Datatables\Datatables;
- use Auth;
- use Illuminate\Support\Facades\Route;
-
-
- class {{ class }} extends Controller
- {
-
-
- private $title = '{{ namespace }}';
- private $route = 'nama_path_awal.nama_path_akhir.';
- private $header = 'Headermu';
- private $sub_header = 'Sub Headermu';
-
- private $namespace_controller = '{{ namespace }}';
- private $url_prefix = 'urlnya routenya';
-
- public function __construct()
- {
- DB::enableQueryLog();
-
-
-
-
-
- }
-
-
-
-
-
- public function index()
- {
- Helper::swal();
-
- $data = [
-
- 'title' => $this->title,
- 'route' => $this->route,
- 'header' => $this->header,
- 'sub_header' => $this->sub_header,
- ];
-
- return view($this->route . 'index', $data);
- }
-
-
- public function getData()
- {
- $query = EloquentMu::All();
- $data_table = Datatables::of($query)
- ->addColumn('aksi', function ($query) {
-
-
- $aksi = '';
- if (Auth::user()->can('Nama_Role_yang_dibuat-update')) {
- $aksi .= "<a href='" . route($this->route . 'update', ['id_di_routenya' => Hashids::encode($query->id)]) . "' class='btn btn-sm btn-primary btn-edit'>Edit</a>";
- }
-
- if (Auth::user()->can('Nama_Role_yang_dibuat-delete')) {
- $aksi .= "<a href='javascript:;' data-route='" . route($this->route . 'delete_action', ['id_di_routenya' => Hashids::encode($query->id)]) . "' class='btn btn-danger btn-sm btn-delete'>Delete</a>";
- }
- return $aksi;
- })
- ->rawColumns(['aksi'])
- ->escapeColumns([])
- ->toJson();
- return $data_table;
- }
-
-
-
- public function create()
- {
- $data = [
-
- 'title' => $this->title,
- 'route' => $this->route,
- 'header' => $this->header,
- 'sub_header' => $this->sub_header,
-
- ];
-
- Helper::swal();
-
- return view($this->route . 'create', $data);
- }
-
-
-
- public function create_action(Request $request)
- {
-
- $post = $request->all();
-
- $rules = [];
-
- $alert = [];
- $validator = Validator::make($post, $rules, $alert);
-
- if ($validator->passes()) {
-
- DB::beginTransaction();
- $query = EloquentMu::create($post);
-
- if ($query) {
- DB::commit();
- $message = 'Berhasil';
- return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
- } else {
- DB::rollback();
- $message = 'Gagal';
- return redirect()->back()->with('error', Helper::parsing_alert($message));
- }
- }
-
- $message = Helper::parsing_alert($validator->errors()->all());
- return redirect()->back()->with('error', $message)->withInput();
- }
-
-
- public function update($id_modelmu)
- {
-
- Helper::swal();
-
-
- $id_modelmu = Hashids::decode($id_modelmu);
- if (!empty($id_modelmu)) {
-
- $cek_data = EloquentMu::where('id', $id_modelmu[0])->first();
-
- if ($cek_data) {
- $data = [
-
- 'title' => $this->title,
- 'route' => $this->route,
- 'header' => $this->header,
- 'sub_header' => $this->sub_header,
- 'data' => $cek_data
- ];
- return view($this->route . 'update', $data);
- }
- $message = 'Id tidak ditemukan atau sudah dihapus';
- return redirect()->back()->with('error', $message);
- }
- $message = 'Id tdak ditemukan';
- return redirect()->back()->with('error', $message);
- }
-
-
-
- public function update_action(Request $request)
- {
- $post = $request->all();
-
- $rules = [];
-
- $alert = [];
- $validator = Validator::make($post, $rules, $alert);
-
- $id_modelmu = Hashids::decode($request['id']);
-
- if (!empty($id_modelmu)) {
-
- $cek_data = EloquentMu::where('id', $id_modelmu[0])->first();
-
- if ($cek_data) {
-
- if ($validator->passes()) {
-
-
- DB::beginTransaction();
- $query = $cek_data->update($post);
-
- if ($query) {
- DB::commit();
- $message = 'Berhasil';
- return redirect(route($this->route . 'index'))->with('success', Helper::parsing_alert($message));
- } else {
- DB::rollback();
- $message = 'Gagal';
- return redirect()->back()->with('error', Helper::parsing_alert($message));
- }
- }
-
- $message = Helper::parsing_alert($validator->errors()->all());
-
- return redirect()->back()->with('error', $message);
- } else {
- $message = 'Id tdak ditemukan';
- return redirect()->back()->with('error', $message);
- }
- } else {
- $message = 'Id tidak boleh kosong';
- return redirect()->back()->with('error', $message);
- }
- }
-
-
-
- public function delete_action($id_modelmu)
- {
- $id_modelmu = Hashids::decode($id_modelmu);
-
-
- if (!empty($id_modelmu)) {
-
- $cek_data = EloquentMu::where('id', $id_modelmu[0])->first();
-
- if ($cek_data) {
- DB::beginTransaction();
- $delete = $cek_data->delete();
- if ($delete) {
- DB::commit();
- $message = 'Succesfully';
- return redirect()->back()->with('success', $message);
- } else {
- DB::rollback();
- $message = 'Gagal';
- return redirect()->back()->with('error', $message);
- }
- }
- $message = 'Id tidak ditemukan atau sudah dihapus';
- return redirect()->back()->with('error', $message);
- }
- $message = 'Id tdak ditemukan';
- return redirect()->back()->with('error', $message);
- }
-
-
- public function route(){
- $route = Route::namespace($this->namespace_controller)
- ->prefix($this->url_prefix)
- ->name($this->route)
- ->group(function () {
- Route::get('/', ['as' => 'index', 'uses' => '{{ class }}@index']);
- Route::get('/get-data/{udd_id?}', ['as' => 'get_data', 'uses' => '{{ class }}@getData']);
- Route::get('/datatables', ['as' => 'datatables', 'uses' => '{{ class }}@datatables']);
- Route::get('/create', ['as' => 'create', 'uses' => '{{ class }}@create']);
- Route::get('/update/{id_di_routenya}', ['as' => 'update', 'uses' => '{{ class }}@update']);
- Route::get('/delete-action/{id_di_routenya}', ['as' => 'delete_action', 'uses' => '{{ class }}@delete_action']);
-
- Route::post('/create-action', ['as' => 'create_action', 'uses' => '{{ class }}@create_action']);
- Route::post('/update-action', ['as' => 'update_action', 'uses' => '{{ class }}@update_action']);
- });
- return $route;
- }
-
- }
|