67 lines
1.7 KiB
PHP
67 lines
1.7 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 brandModel extends Model
|
|
{
|
|
protected $primaryKey = 'id_brand';
|
|
protected $table = 'reff_brand';
|
|
public $timestamps = false;
|
|
|
|
public function initData($request,$route)
|
|
{
|
|
// INIT DB
|
|
$data['title'] = 'Brand';
|
|
$data['actButton'] = ['edit'];
|
|
$data['tableHead'] =
|
|
array(
|
|
["ID","all","id_brand"],
|
|
["Nama Brand","all","name_brand"],
|
|
["Act","all","action"]
|
|
);
|
|
$cGlobal = new Controller();
|
|
|
|
$data['db'] = $this->table;
|
|
$data['db_key'] = $this->primaryKey;
|
|
$data['route'] = $route;
|
|
|
|
$dtable = \DB::select("SELECT * from reff_brand order by id_brand desc");
|
|
|
|
// LIST DATA TABLE
|
|
$data['data_table'] = $dtable;
|
|
|
|
// FORM FIELD FOR STORE
|
|
$data['set_field'] = [
|
|
'name_brand' => $cGlobal->cleanString($request->post('name_brand'))
|
|
];
|
|
|
|
// GET DATA FOR EDIT
|
|
if ($request->post('id')) {
|
|
$data['get_data_edit'] = collect(\DB::select("SELECT * FROM reff_brand where id_brand = ?",[$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;
|
|
}
|
|
|
|
}
|