@@ -28,10 +28,11 @@ |
||
| 28 | 28 | { |
| 29 | 29 | $this->authorize('show', Deviceimage::class); |
| 30 | 30 | |
| 31 | - if (Storage::disk('private')->exists('deviceimage/'.$device_id)) |
|
| 32 | - $image = Image::make(Storage::disk('private')->get('deviceimage/'.$device_id)); |
|
| 33 | - else |
|
| 34 | - $image = Image::make('img/video_not_found.jpg'); |
|
| 31 | + if (Storage::disk('private')->exists('deviceimage/'.$device_id)) { |
|
| 32 | + $image = Image::make(Storage::disk('private')->get('deviceimage/'.$device_id)); |
|
| 33 | + } else { |
|
| 34 | + $image = Image::make('img/video_not_found.jpg'); |
|
| 35 | + } |
|
| 35 | 36 | |
| 36 | 37 | return $image->response(); |
| 37 | 38 | } |
@@ -133,21 +133,24 @@ |
||
| 133 | 133 | $user->name = $request->input('name'); |
| 134 | 134 | $user->email = $request->input('email'); |
| 135 | 135 | $user->phone = $request->input('phone'); |
| 136 | - if ($request->input('password') != '') |
|
| 137 | - $user->password = bcrypt($request->input('password')); |
|
| 138 | - if (Auth::user()->can('updateRole', User::class)) |
|
| 139 | - $user->role = $request->input('role'); |
|
| 136 | + if ($request->input('password') != '') { |
|
| 137 | + $user->password = bcrypt($request->input('password')); |
|
| 138 | + } |
|
| 139 | + if (Auth::user()->can('updateRole', User::class)) { |
|
| 140 | + $user->role = $request->input('role'); |
|
| 141 | + } |
|
| 142 | + } else { |
|
| 143 | + $user->preferred_device_id = $request->input('preferred_device_id'); |
|
| 140 | 144 | } |
| 141 | - else |
|
| 142 | - $user->preferred_device_id = $request->input('preferred_device_id'); |
|
| 143 | 145 | |
| 144 | 146 | $user->save(); |
| 145 | 147 | |
| 146 | - if (\Request::ajax()) |
|
| 147 | - return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
| 148 | - else |
|
| 149 | - return redirect()->route('user.show', $user->id) |
|
| 148 | + if (\Request::ajax()) { |
|
| 149 | + return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
| 150 | + } else { |
|
| 151 | + return redirect()->route('user.show', $user->id) |
|
| 150 | 152 | ->with('success', 'User updated successfully'); |
| 153 | + } |
|
| 151 | 154 | } |
| 152 | 155 | |
| 153 | 156 | /** |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | //Create a new site |
| 112 | 112 | $site = Site::create([ 'name' => $request->input('new_site_name') ]); |
| 113 | 113 | $site_id = $site->id; |
| 114 | + } else { |
|
| 115 | + $site_id = $request->input('site_id'); |
|
| 114 | 116 | } |
| 115 | - else |
|
| 116 | - $site_id = $request->input('site_id'); |
|
| 117 | 117 | |
| 118 | 118 | //Get the location id of the old or newly created location |
| 119 | 119 | if (!empty($request->input('new_location_name'))) |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | //Create a new location |
| 122 | 122 | $location = Location::create([ 'name' => $request->input('new_location_name'), 'site_id' => $site_id ]); |
| 123 | 123 | $location_id = $location->id; |
| 124 | + } else { |
|
| 125 | + $location_id = $request->input('location_id'); |
|
| 124 | 126 | } |
| 125 | - else |
|
| 126 | - $location_id = $request->input('location_id'); |
|
| 127 | 127 | |
| 128 | 128 | //Update the device |
| 129 | 129 | $device->location_id = $location_id; |
@@ -141,29 +141,32 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | $this->authorize('updateCommand', Device::class); |
| 143 | 143 | //If device is currently opening, closing or in an error state don't update command |
| 144 | - if (!$device->isReadyForCommand()) |
|
| 145 | - return response()->json("Device is currently in use.", 503); |
|
| 144 | + if (!$device->isReadyForCommand()) { |
|
| 145 | + return response()->json("Device is currently in use.", 503); |
|
| 146 | + } |
|
| 146 | 147 | |
| 147 | 148 | $command = $request->input('command'); |
| 148 | 149 | |
| 149 | 150 | //If command is to unlock the device then check if the device should be open or closed based on the schedule |
| 150 | 151 | if ($request->command === 'unlock') |
| 151 | 152 | { |
| 152 | - if ($device->isDuringScheduleOpen()) |
|
| 153 | - $command = 'open'; |
|
| 154 | - else |
|
| 155 | - $command = 'close'; |
|
| 153 | + if ($device->isDuringScheduleOpen()) { |
|
| 154 | + $command = 'open'; |
|
| 155 | + } else { |
|
| 156 | + $command = 'close'; |
|
| 157 | + } |
|
| 156 | 158 | } |
| 157 | 159 | $device->cover_command = $command; |
| 158 | 160 | } |
| 159 | 161 | |
| 160 | 162 | $device->save(); |
| 161 | 163 | |
| 162 | - if (\Request::ajax()) |
|
| 163 | - return response()->json([ 'success' => 'Device updated successfully' ]); |
|
| 164 | - else |
|
| 165 | - return redirect()->route('device.show', $device->id) |
|
| 164 | + if (\Request::ajax()) { |
|
| 165 | + return response()->json([ 'success' => 'Device updated successfully' ]); |
|
| 166 | + } else { |
|
| 167 | + return redirect()->route('device.show', $device->id) |
|
| 166 | 168 | ->with('success', 'Device updated successfully'); |
| 169 | + } |
|
| 167 | 170 | } |
| 168 | 171 | |
| 169 | 172 | /** |
@@ -51,10 +51,11 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function show(User $user, User $user2) |
| 53 | 53 | { |
| 54 | - if ($user->isAdmin()) |
|
| 55 | - return true; |
|
| 56 | - else |
|
| 57 | - return $user->isUser() && $user->id === $user2->id; |
|
| 54 | + if ($user->isAdmin()) { |
|
| 55 | + return true; |
|
| 56 | + } else { |
|
| 57 | + return $user->isUser() && $user->id === $user2->id; |
|
| 58 | + } |
|
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | /** |
@@ -66,10 +67,11 @@ discard block |
||
| 66 | 67 | */ |
| 67 | 68 | public function edit(User $user, User $user2) |
| 68 | 69 | { |
| 69 | - if ($user->isAdmin()) |
|
| 70 | - return true; |
|
| 71 | - else |
|
| 72 | - return $user->isUser() && $user->id === $user2->id; |
|
| 70 | + if ($user->isAdmin()) { |
|
| 71 | + return true; |
|
| 72 | + } else { |
|
| 73 | + return $user->isUser() && $user->id === $user2->id; |
|
| 74 | + } |
|
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | /** |
@@ -81,10 +83,11 @@ discard block |
||
| 81 | 83 | */ |
| 82 | 84 | public function update(User $user, User $user2) |
| 83 | 85 | { |
| 84 | - if ($user->isAdmin()) |
|
| 85 | - return true; |
|
| 86 | - else |
|
| 87 | - return $user->isUser() && $user->id === $user2->id; |
|
| 86 | + if ($user->isAdmin()) { |
|
| 87 | + return true; |
|
| 88 | + } else { |
|
| 89 | + return $user->isUser() && $user->id === $user2->id; |
|
| 90 | + } |
|
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | /** |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | { |
| 46 | 46 | $this->registerPolicies(); |
| 47 | 47 | |
| 48 | - Gate::define('index-dashboard', function ($user) { |
|
| 48 | + Gate::define('index-dashboard', function($user) { |
|
| 49 | 49 | return $user->isUser(); |
| 50 | 50 | }); |
| 51 | 51 | } |