<?php
 namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; use Session; use Validator; use Redirect; class Calander extends Setup { public function __construct() { parent::__construct(); } public function edit(Request $request) { if(check_user_access('calander_right') === FALSE){ Redirect::to('/')->send(); } $this->data["editing_data"] = fetch_calander(); $this->data["title"] = print_lang($this->data["app_lang"],'calander'); $this->data["pageToLoad"] = "calander/edit.php"; $this->data["activeLink"] = "settings"; $this->load_view($this->data); } public function update(Request $request) { $validator = Validator::make($request->request->all(), [ 'name' => 'required', ]); $validator->validate(); $active_branch_id = active_branch_id(); $db_array = array( 'name' => $request->name, ); $calander_data = DB::table('calander')->where('branch',$active_branch_id)->get(); if($calander_data->count() > 0) { update_table('calander','branch',$active_branch_id,$db_array); } else { $db_array['branch'] = $active_branch_id; insert_table('calander',$db_array); } echo json_encode(array('status' => 'success', 'mood' => 'update', 'message_head' => print_lang($this->data["app_lang"],'calander_updated'), 'message_body' => print_lang($this->data["app_lang"],'calander_updated_successfully'))); } }