| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Http\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use App\Models\Providers; | 
					
						
							|  |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | use Illuminate\Support\Facades\Cache; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ProvidersController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-09 15:39:03 +10:00
										 |  |  |         $providers = Providers::allProviders(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return view('providers.index', compact(['providers'])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function create() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return view('providers.create'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function store(Request $request) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $request->validate([ | 
					
						
							| 
									
										
										
										
											2022-11-08 10:39:05 +11:00
										 |  |  |             'provider_name' => 'required|string|min:2|max:255' | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Providers::create([ | 
					
						
							|  |  |  |             'name' => $request->provider_name | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 15:39:03 +10:00
										 |  |  |         Cache::forget('providers'); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return redirect()->route('providers.index') | 
					
						
							|  |  |  |             ->with('success', 'Provider Created Successfully.'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |     public function show(Providers $provider) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-15 21:01:02 +10:00
										 |  |  |         $data = Providers::showServicesForProvider($provider->id); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return view('providers.show', compact(['provider', 'data'])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     public function destroy(Providers $provider) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |         if ($provider->delete()) { | 
					
						
							|  |  |  |             Cache::forget('providers'); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             return redirect()->route('providers.index') | 
					
						
							|  |  |  |                 ->with('success', 'Provider was deleted Successfully.'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return redirect()->route('providers.index') | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             ->with('error', 'Provider was not deleted.'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |