Advertisement
masdhan

BankController

Sep 10th, 2020
1,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Controllers;
  4.  
  5. use App\Models\BankModel;
  6.  
  7. class BankController extends BaseController
  8. {
  9.     public function __construct()
  10.     {
  11.         $this->bankModel = new BankModel();
  12.     }
  13.     public function index()
  14.     {
  15.         $data = [
  16.             'title' => 'Halaman Bank',
  17.             'banks' => $this->bankModel->findAll()
  18.         ];
  19.         return view('admin/bank/index', $data);
  20.     }
  21.  
  22.     public function create()
  23.     {
  24.         $validation = \Config\Services::validation();
  25.         $data = [
  26.             'title' => 'Tambah Bank',
  27.             'validation' => $validation
  28.         ];
  29.         return view('admin/bank/create', $data);
  30.     }
  31.  
  32.     public function save()
  33.     {
  34.         if (!$this->validate([
  35.             'jenis_bank' => [
  36.                 'rules' => 'required',
  37.                 'errors' => [
  38.                     'required' => 'input tidak boleh kosong'
  39.                 ]
  40.             ],
  41.             'no_rekening' => [
  42.                 'rules' => 'required',
  43.                 'errors' => [
  44.                     'required' => 'input tidak boleh kosong'
  45.                 ]
  46.             ],
  47.             'nama_pemilik' => [
  48.                 'rules' => 'required',
  49.                 'errors' => [
  50.                     'required' => 'input tidak boleh kosong'
  51.                 ]
  52.             ]
  53.         ])) {
  54.             // $validation = \Config\Services::validation();
  55.             // dd($validation);
  56.             return redirect()->to('/admin/bank/create')->withInput();
  57.         }
  58.         $this->bankModel->save([
  59.             'jenis_bank' => $this->request->getPost('jenis_bank'),
  60.             'no_rekening' => $this->request->getPost('no_rekening'),
  61.             'nama_pemilik' => $this->request->getPost('nama_pemilik'),
  62.         ]);
  63.         session()->setFlashdata('pesan', 'Data berhasil ditambah!');
  64.         return redirect()->to('/admin/bank');
  65.     }
  66.  
  67.     //--------------------------------------------------------------------
  68.  
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement