74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Datatables, DB;
|
|
use Exception;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
use Yajra\DataTables\DataTables as DT;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
class bankModel extends Model
|
|
{
|
|
protected $primaryKey = 'id';
|
|
protected $table = 'reff_bank';
|
|
public $timestamps = false;
|
|
|
|
public function initData($request,$route)
|
|
{
|
|
// INIT DB
|
|
$data['title'] = 'Bank';
|
|
$data['actButton'] = ['edit','active'];
|
|
$data['tableHead'] =
|
|
array(
|
|
["Bank Code","all","bank_code"],
|
|
["Bank Name","all","bank_name"],
|
|
["Status","all","is_active"],
|
|
["Act","all","action"]
|
|
);
|
|
|
|
|
|
$data['db'] = $this->table;
|
|
$data['db_key'] = $this->primaryKey;
|
|
$data['route'] = $route;
|
|
|
|
$dtable = \DB::select("SELECT * from reff_bank order by id desc");
|
|
|
|
// LIST DATA TABLE
|
|
$data['data_table'] = $dtable;
|
|
|
|
// FORM FIELD FOR STORE
|
|
$data['set_field'] = [
|
|
'bank_name' => $request->post('bank_name'),
|
|
'bank_code' => $request->post('bank_code'),
|
|
'is_active' => $request->post('is_active')
|
|
];
|
|
|
|
// GET DATA FOR EDIT
|
|
if ($request->post('id')) {
|
|
$data['get_data_edit'] = collect(\DB::select("SELECT * FROM reff_bank where id = ?",[$request->post('id')]))->first();
|
|
}
|
|
|
|
foreach($data['tableHead'] as $v){
|
|
$arrHead[] = $v[2];
|
|
}
|
|
$data['head'] = implode(",",$arrHead);
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getDT($data,$init)
|
|
{
|
|
$dt = DT::of($data);
|
|
$dt->editColumn('is_active',function($data) {
|
|
return ($data->is_active == true) ? '<span class="label label-success label-inline mr-2">Active</span>':'<span class="label label-danger label-inline mr-2">Non-Active</span>';
|
|
});
|
|
|
|
return $dt;
|
|
}
|
|
|
|
}
|