route; $data['title'] = $this->title; return view($this->template.'.index',$data); } public function grid() { $data = Agency::all(); $_data = []; foreach ($data as $key => $row) { $btn = 'Edit'; $btn .= '
'; $btn .= csrf_field(); $btn .= method_field('DELETE'); $btn .= ''; $btn .= '
'; if ($row->row_status == 1) { $status = 'Aktif'; } else { $status = 'Tidak Aktif'; } $_data[] = [ 'no' => $key+1, 'name' => $row->name, 'scope' => $row->scope, 'status' => $status, 'action' => @$btn, ]; } return response()->json($_data); } /** * Show the form for creating a new resource. */ public function create() { $data['route'] = $this->route; $data['title'] = $this->title; return view($this->template.'.form',$data); } public function update($id = null) { $keyId = decode_id($id); $data['title'] = $this->title; $data['route'] = $this->route; $data['keyId'] = $id; $data['item'] = Agency::where('id',$keyId)->first(); return view($this->template.'.form',$data); } /** * Store a newly created resource in storage. */ public function store(Request $request) { $request->validate([ 'name' => 'required|string|max:255', 'scope' => 'nullable|string', ]); try { if(@$request->secure_id){ $ag = Agency::find(decode_id(@$request->secure_id)); $ag->name = $request->name; $ag->scope = $request->scope; $ag->save(); }else{ $ag = new Agency; $ag->name = $request->name; $ag->scope = $request->scope; $ag->row_status = 1; $ag->save(); } return redirect()->route($this->route.'.index')->with('success', 'Agency berhasil ditambahkan.'); } catch (\Exception $e) { return back()->withErrors(['error' => 'Agency gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]); } } /** * Display the specified resource. */ public function show(string $id) { // } /** * Show the form for editing the specified resource. */ public function edit(string $id) { $data['ar'] = Agency::find($id); $data['route'] = $this->route; $data['title'] = $this->title; return view($this->template.'.form', $data); } /** * Update the specified resource in storage. */ /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }