Advertisement
Guest User

gatecontroller.php

a guest
Oct 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2. namespace App\Http\Controllers;
  3.  
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Str;
  6.  
  7. //Model
  8. use App\Models\Location as Location;
  9. use App\Models\Gate as Gate;
  10.  
  11. class GateController extends Controller{
  12.     protected $data;
  13.  
  14.     public function Index(){
  15.         $this->data['list_location'] = Location::all();
  16.         $this->data['list_gate']     = Gate::all();
  17.         return view('pages.gate.index', $this->data);
  18.     }
  19.  
  20.     public function Detail(Request $req){
  21.         $input  = $req->all();
  22.         $res    = Gate::where("id_gate",$input['id'])->first();
  23.         $data   = array('id'=>$res->id_gate,'id_location'=>$res->id_location,'gate'=>$res->gate_name);
  24.         echo json_encode($data);    
  25.     }
  26.  
  27.     public function Save(Request $req){
  28.         $input=$req->all();
  29.         if(isset($input['id_parameter'])){
  30.                Gate::where(['id_gate'=>$input['id_parameter']])
  31.                             ->update(
  32.                                 [
  33.                                     'id_location'            => $input['lokasi'],
  34.                                     'gate_name'              => $input['gate_name'],
  35.                                     'updated_by'             => '1'
  36.                                 ]
  37.                             );
  38.                 echo "OK"; 
  39.         }
  40.         else {
  41.              $res  = new Gate;
  42.  
  43.              $res->id_gate                      = "gt_".date("ymdhis")."_".rand(10000, 99999);
  44.              $res->id_location                  = $input['lokasi'];
  45.              $res->gate_name                    = $input['gate_name'];
  46.              $res->created_by                   = "1";
  47.              $res->updated_by                   = "1";
  48.              $res->save();
  49.              echo "OK";
  50.         }
  51.  
  52.     }
  53.  
  54.     public function Destroy(Request $req){
  55.         $input=$req->all();
  56.         Gate::where(['id_gate'=>$input['id_parameter']])->delete();
  57.         echo "OK"; 
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement