gundambison

controller (1)

Nov 18th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.92 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Admin\Agen;
  4.  
  5.  
  6. use Backpack\CRUD\app\Http\Controllers\CrudController;
  7.  
  8. // VALIDATION: change the requests to match your own file names if you need form validation
  9. use App\Http\Requests\PerusahaanRequest as StoreRequest;
  10. use App\Http\Requests\PerusahaanRequest as UpdateRequest;
  11.  
  12. class AgenKerjasamaController extends CrudController{
  13.     public function setup()
  14.     {
  15.         /*
  16.         |--------------------------------------------------------------------------
  17.         | CrudPanel Basic Information
  18.         |--------------------------------------------------------------------------
  19.         */
  20.         $this->crud->setModel('App\Models\Agent_kerjasama');
  21.         $this->crud->setRoute(config('backpack.base.route_prefix') . '/agen/kerjasama');
  22.         $this->crud->setEntityNameStrings('Agent Cabang', 'Agent Cabang');
  23.         /*
  24.         |--------------------------------------------------------------------------
  25.         | CrudPanel Configuration
  26.         |--------------------------------------------------------------------------
  27.         */
  28.         $this->crud->addColumn([
  29.             'type' => 'text',
  30.             'name' => 'nama_perusahaan'            ,
  31.             'label' => 'Nama Agent'
  32.         ]);
  33.  
  34.         $this->crud->addColumn([
  35.             'type' => 'text',
  36.             'name' => 'no_telp',
  37.             'label' => 'Kontak'
  38.         ]);
  39.  
  40.         $this->crud->addColumn([
  41.             'type' => 'text',
  42.             'name' => 'nama_pimpinan',
  43.             'label' => 'Nama Pimpinan'
  44.         ]);
  45.  
  46.         $this->crud->addColumn([
  47.             'name' => 'status_perusahaan',
  48.             'label' => 'Status Perusahaan',
  49.             'type' => 'select_from_array',
  50.             'options' => [
  51.                 '0' => 'Draft',
  52.                 '1' => 'Aktif',
  53.                 '2' => 'Tidak Aktif'
  54.             ],
  55.             'tab' => 'Status'
  56.         ]);
  57.  
  58.         $this->crud->addColumn([
  59.             'name' => 'agen_type',
  60.             'label' => 'Tipe Agent',
  61.             'type' => 'select_from_array',
  62.             'options' => [
  63.                 '1' => 'Alfa',
  64.                 '2' => 'Izin',
  65.                 '3' => 'Kerjasama'
  66.             ],
  67.             'tab' => 'Status'
  68.         ]);
  69.  
  70.         //============OTHER CONFIG
  71.         $this->crud->removeAllButtons();
  72.         $this->crud->addField([
  73.             'type' => 'hidden',
  74.             'name' => 'token',
  75.             'label' => 'Hidden',
  76.             'value' => strtoupper(substr(uniqid(), 0, 6))
  77.         ]);
  78.         if(isset(backpack_user()->user_perusahaan->perusahaan->id)){
  79.           $this->crud->addField([
  80.               'type' => 'hidden',
  81.               'name' => 'parent_id',
  82.               'label' => 'Parent ID',
  83.               'value' => backpack_user()->user_perusahaan->perusahaan->id,
  84.           ]);
  85.         }
  86.  
  87.         $this->crud->addButtonFromModelFunction('line', 'show_agent_detail', 'showAgentDetail', 'beginning'); // add a button whose HTML is returned by a method in the CRUD model
  88.         $this->crud->allowAccess('show');
  89.         // add asterisk for fields that are required in PerusahaanRequest
  90.         $this->crud->setRequiredFields(StoreRequest::class, 'create');
  91.         $this->crud->setRequiredFields(UpdateRequest::class, 'edit');
  92.     }
  93.  
  94.     public function store(StoreRequest $request)
  95.     {
  96.         // your additional operations before save here
  97.         $redirect_location = parent::storeCrud($request);
  98.         // your additional operations after save here
  99.         // use $this->data['entry'] or $this->crud->entry
  100.         return $redirect_location;
  101.     }
  102.  
  103.     public function update(UpdateRequest $request)
  104.     {
  105.         // your additional operations before save here
  106.         $redirect_location = parent::updateCrud($request);
  107.         // your additional operations after save here
  108.         // use $this->data['entry'] or $this->crud->entry
  109.         return $redirect_location;
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment