| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Http\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use App\Models\Locations; | 
					
						
							|  |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | use Illuminate\Support\Facades\Cache; | 
					
						
							|  |  |  | use Illuminate\Support\Facades\DB; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LocationsController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-09 15:39:29 +10:00
										 |  |  |         $locations = Locations::allLocations(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return view('locations.index', compact(['locations'])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function create() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return view('locations.create'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function store(Request $request) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $request->validate([ | 
					
						
							| 
									
										
										
										
											2022-11-08 10:39:05 +11:00
										 |  |  |             'location_name' => 'required|string|min:2|max:255' | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Locations::create([ | 
					
						
							|  |  |  |             'name' => $request->location_name | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 15:00:33 +10:00
										 |  |  |         Cache::forget('locations'); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return redirect()->route('locations.index') | 
					
						
							|  |  |  |             ->with('success', 'Location Created Successfully.'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |     public function show(Locations $location) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $servers = DB::table('servers as s') | 
					
						
							| 
									
										
										
										
											2023-08-18 19:33:26 +10:00
										 |  |  |             ->where('s.location_id', $location->id) | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |             ->get(['s.id', 's.hostname']) | 
					
						
							|  |  |  |             ->toArray(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $shared = DB::table('shared_hosting as s') | 
					
						
							| 
									
										
										
										
											2023-08-18 19:33:26 +10:00
										 |  |  |             ->where('s.location_id', $location->id) | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |             ->get(['s.id', 's.main_domain as main_domain_shared']) | 
					
						
							|  |  |  |             ->toArray(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $reseller = DB::table('reseller_hosting as r') | 
					
						
							| 
									
										
										
										
											2023-08-18 19:33:26 +10:00
										 |  |  |             ->where('r.location_id', $location->id) | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |             ->get(['r.id', 'r.main_domain as main_domain_reseller']) | 
					
						
							|  |  |  |             ->toArray(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $data = array_merge($servers, $shared, $reseller); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return view('locations.show', compact(['location', 'data'])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     public function destroy(Locations $location) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |         if ($location->delete()){ | 
					
						
							|  |  |  |             Cache::forget('locations'); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             return redirect()->route('locations.index') | 
					
						
							|  |  |  |                 ->with('success', 'Location was deleted Successfully.'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return redirect()->route('locations.index') | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             ->with('error', 'Location was not deleted.'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | } |