| @@ 160-181 (lines=22) @@ | ||
| 157 | * @param string $id |
|
| 158 | * @return \Illuminate\Http\RedirectResponse |
|
| 159 | */ |
|
| 160 | public function destroy($id) |
|
| 161 | { |
|
| 162 | $device = Device::withTrashed()->findOrFail($id); |
|
| 163 | ||
| 164 | if ($device->trashed()) |
|
| 165 | { |
|
| 166 | //If the device was already deleted then permanently delete it |
|
| 167 | $device->forceDelete($device->id); |
|
| 168 | } |
|
| 169 | else |
|
| 170 | { |
|
| 171 | //Remove the location from the device |
|
| 172 | $device->location_id = null; |
|
| 173 | $device->save(); |
|
| 174 | ||
| 175 | //Soft delete the device the first time |
|
| 176 | $device->delete(); |
|
| 177 | } |
|
| 178 | ||
| 179 | return redirect()->route('device.index') |
|
| 180 | ->with('success','Device deleted successfully'); |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * Restores a device. |
|
| @@ 144-158 (lines=15) @@ | ||
| 141 | * @param string $id |
|
| 142 | * @return \Illuminate\Http\RedirectResponse |
|
| 143 | */ |
|
| 144 | public function destroy($id) |
|
| 145 | { |
|
| 146 | $user = User::withTrashed()->findOrFail($id); |
|
| 147 | ||
| 148 | if ($user->trashed()) { |
|
| 149 | //If the user was already deleted then permanently delete it |
|
| 150 | $user->forceDelete($user->id); |
|
| 151 | } else { |
|
| 152 | //Soft delete the user the first time |
|
| 153 | $user->delete(); |
|
| 154 | } |
|
| 155 | ||
| 156 | return redirect()->route('user.index') |
|
| 157 | ->with('success','User deleted successfully'); |
|
| 158 | } |
|
| 159 | ||
| 160 | /** |
|
| 161 | * Restores a user. |
|