pos-gis/app/Models/kotaModel.php
2024-10-07 13:13:42 +07:00

74 lines
1.8 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 App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\User as Authenticatable;
class kotaModel extends Model
{
protected $primaryKey = 'city_id';
protected $table = 'reff_city';
public $timestamps = false;
public function initData($request,$route)
{
// INIT DB
$data['title'] = 'Kota';
$data['actButton'] = ['edit'];
$data['tableHead'] =
array(
["Nama Kota","all","city_nm"],
["Kode Dati","all","dati_code"],
["Act","all","action"]
);
$data['db'] = $this->table;
$data['db_key'] = $this->primaryKey;
$data['route'] = $route;
$dtable = \DB::select("SELECT * from reff_city order by city_id desc");
$cGlobal = new Controller();
// LIST DATA TABLE
$data['data_table'] = $dtable;
// FORM FIELD FOR STORE
$data['set_field'] = [
'city_nm' => $cGlobal->cleanString($request->post('city_nm')),
'dati_code' => $cGlobal->cleanString($request->post('dati_code'))
];
// GET DATA FOR EDIT
if ($request->post('id')) {
$data['get_data_edit'] = collect(\DB::select("SELECT * FROM reff_city where city_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);
return $dt;
}
}