pos-gis/app/Models/vehicleModel.php

73 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2024-10-07 06:13:42 +00:00
<?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 vehicleModel extends Model
{
protected $primaryKey = 'vehicle_type_id';
protected $table = 'reff_vehicle_type';
public $timestamps = false;
public function initData($request,$route)
{
// INIT DB
$data['title'] = 'Vehicle';
$data['actButton'] = ['edit','active'];
$data['tableHead'] =
array(
["ID","all","vehicle_type_id"],
["Vehicle Name","all","vehicle_type_nm"],
["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_vehicle_type order by vehicle_type_id desc");
// LIST DATA TABLE
$data['data_table'] = $dtable;
// FORM FIELD FOR STORE
$data['set_field'] = [
'vehicle_type_nm' => $request->post('vehicle_type_nm'),
'is_active' => $request->post('is_active')
];
// GET DATA FOR EDIT
if ($request->post('id')) {
$data['get_data_edit'] = collect(\DB::select("SELECT * FROM reff_vehicle_type where vehicle_type_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;
}
}