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