public function update(Request $request, $id)
 {
     $this->update_validation_rules($request);
     $date_open = $this->saved_date_format($request->input('date_open'));
     $request->merge(array('date_open' => $date_open));
     $officeUpdate = $request->input();
     $office = Office::find($id);
     $office->update($officeUpdate);
     $imageName = $office->id . '-office.' . $request->file('url_photo')->getClientOriginalExtension();
     $request->file('url_photo')->move(base_path() . '/public/images/offices/', $imageName);
     Session::flash('flash_message', 'Data berhasil diupdate!');
     return redirect('master/offices');
 }
Exemple #2
0
 public function getAccessableOfficesWhereUserIs($role)
 {
     switch ($role) {
         case self::MANAGER:
             return $this->offices;
             break;
         case self::COMDIR:
             /* Коммерческий директор имеет доступ к офисам своего региона */
             $offices = [];
             $regions = Region::find(['user_id' => 'id'])->innerJoin('questionlist_users_to_regions utr', 'utr.region_id=' . Region::tableName() . '.id', ['utr.user_id' => $this->id])->with('offices')->all();
             if (!$regions) {
                 return;
             }
             foreach ($regions as $region) {
                 $offices = array_merge($offices, $region->offices);
             }
             return $offices;
             break;
         case self::ADMIN:
             /* Админ имеет доступ к всем офисам */
             if (!$this->isAdmin) {
                 return;
             }
             return Office::find()->all();
             break;
     }
 }