| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Http\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use App\Models\OS; | 
					
						
							|  |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2022-03-06 00:54:24 +11:00
										 |  |  | use Illuminate\Support\Facades\Cache; | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | class OsController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-09 14:57:38 +10:00
										 |  |  |         $os = OS::allOS(); | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  |         return view('os.index', compact(['os'])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function create() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return view('os.create'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function store(Request $request) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $request->validate([ | 
					
						
							| 
									
										
										
										
											2022-11-08 10:39:05 +11:00
										 |  |  |             'os_name' => 'required|string|min:2|max:255' | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         OS::create([ | 
					
						
							|  |  |  |             'name' => $request->os_name | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 14:57:38 +10:00
										 |  |  |         Cache::forget('operating_systems'); | 
					
						
							| 
									
										
										
										
											2022-03-06 00:54:24 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  |         return redirect()->route('os.index') | 
					
						
							|  |  |  |             ->with('success', 'OS Created Successfully.'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-19 23:57:48 +11:00
										 |  |  |     public function destroy(OS $o) | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |         if ($o->delete()) { | 
					
						
							|  |  |  |             Cache::forget('operating_systems'); | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             return redirect()->route('os.index') | 
					
						
							|  |  |  |                 ->with('success', 'OS was deleted Successfully.'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-06 00:54:24 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  |         return redirect()->route('os.index') | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             ->with('error', 'OS was not deleted.'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-19 23:42:59 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | } |