Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Str;
- //Model
- use App\Models\Location as Location;
- use App\Models\Gate as Gate;
- class GateController extends Controller{
- protected $data;
- public function Index(){
- $this->data['list_location'] = Location::all();
- $this->data['list_gate'] = Gate::all();
- return view('pages.gate.index', $this->data);
- }
- public function Detail(Request $req){
- $input = $req->all();
- $res = Gate::where("id_gate",$input['id'])->first();
- $data = array('id'=>$res->id_gate,'id_location'=>$res->id_location,'gate'=>$res->gate_name);
- echo json_encode($data);
- }
- public function Save(Request $req){
- $input=$req->all();
- if(isset($input['id_parameter'])){
- Gate::where(['id_gate'=>$input['id_parameter']])
- ->update(
- [
- 'id_location' => $input['lokasi'],
- 'gate_name' => $input['gate_name'],
- 'updated_by' => '1'
- ]
- );
- echo "OK";
- }
- else {
- $res = new Gate;
- $res->id_gate = "gt_".date("ymdhis")."_".rand(10000, 99999);
- $res->id_location = $input['lokasi'];
- $res->gate_name = $input['gate_name'];
- $res->created_by = "1";
- $res->updated_by = "1";
- $res->save();
- echo "OK";
- }
- }
- public function Destroy(Request $req){
- $input=$req->all();
- Gate::where(['id_gate'=>$input['id_parameter']])->delete();
- echo "OK";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement