Advertisement
gundambison

model (agent)

Nov 18th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.71 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Models;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6. use Backpack\CRUD\CrudTrait;
  7.  
  8. class Agent_kerjasama extends Model
  9. {
  10.     use CrudTrait;
  11.  
  12.     /*
  13.     |--------------------------------------------------------------------------
  14.     | GLOBAL VARIABLES
  15.     |--------------------------------------------------------------------------
  16.     */
  17.  
  18.     protected $table = 'perusahaans';
  19.     // protected $primaryKey = 'id';
  20.     // public $timestamps = false;
  21.     // protected $guarded = ['id'];
  22.     protected $fillable = [
  23.         'id',
  24.         'agen_type',
  25.         'parent_id',
  26.         'nama_perusahaan',
  27.         'jenis_izin',
  28.         'nomor_izin_usaha',
  29.         'no_telp',
  30.         'npwp',
  31.         'negara_id',
  32.         'province_id',
  33.         'regency_id',
  34.         'district_id',
  35.         'village_id',
  36.         'alamat',
  37.         'latitude',
  38.         'longitude',
  39.         'nama_pimpinan',
  40.         'no_ktp_pimpinan',
  41.         'file_surat_izin',
  42.         'file_npwp',
  43.         'file_ktp_pimpinan',
  44.         'status_perusahaan',
  45.         'token'
  46.     ];
  47.     // protected $hidden = [];
  48.     // protected $dates = [];
  49.  
  50.     /*
  51.     |--------------------------------------------------------------------------
  52.     | FUNCTIONS
  53.     |--------------------------------------------------------------------------
  54.     */
  55.  
  56.  
  57.     /*
  58.     |--------------------------------------------------------------------------
  59.     | RELATIONS
  60.     |--------------------------------------------------------------------------
  61.     */
  62.     public function perusahaan()
  63.     {
  64.         return $this->belongsTo('App\Models\Perusahaan', 'parent_id', 'id');
  65.     }
  66.  
  67.     public function province()
  68.     {
  69.         return $this->belongsTo('App\Models\Province');
  70.     }
  71.  
  72.     public function regency()
  73.     {
  74.         return $this->belongsTo('App\Models\Regency');
  75.     }
  76.  
  77.     public function district()
  78.     {
  79.         return $this->belongsTo('App\Models\District');
  80.     }
  81.     /*
  82.     |--------------------------------------------------------------------------
  83.     | SCOPES
  84.     |--------------------------------------------------------------------------
  85.     */
  86.  
  87.     /*
  88.     |--------------------------------------------------------------------------
  89.     | ACCESORS
  90.     |--------------------------------------------------------------------------
  91.     */
  92.  
  93.     /*
  94.     |--------------------------------------------------------------------------
  95.     | MUTATORS
  96.     |--------------------------------------------------------------------------
  97.     */
  98.     public function setFileSuratIzinAttribute($value)
  99.     {
  100.         $attribute_name = "file_surat_izin";
  101.         $disk = "public";
  102.         $destination_path = "file-surat-izin/" . date('Y') . '/' . date('m');
  103.  
  104.         $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
  105.     }
  106.    
  107.     public function setFileNpwpAttribute($value)
  108.     {
  109.         $attribute_name = "file_npwp";
  110.         $disk = "public";
  111.         $destination_path = "file-npwp/" . date('Y') . '/' . date('m');
  112.  
  113.         $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
  114.     }
  115.  
  116.     public function setFileKtpPimpinanAttribute($value)
  117.     {
  118.         $attribute_name = "file_ktp_pimpinan";
  119.         $disk = "public";
  120.         $destination_path = "file-ktp-pimpinan/" . date('Y') . '/' . date('m');
  121.  
  122.         $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
  123.     }
  124.  
  125.     public function showAgentDetail($crud = false)
  126.     {
  127.         return '<a class="btn btn-xs btn-default" target="_blank" href="'.route('crud.register/agen-berizin.show', $this->id).'" data-toggle="tooltip" title="Just a demo custom button."><i class="fa fa-search"></i> Lihat Detil</a>';
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement