my-idlers/app/Http/Controllers/ProvidersController.php

60 lines
1.3 KiB
PHP
Raw Normal View History

<?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;
class ProvidersController extends Controller
{
public function index()
{
$providers = Providers::allProviders();
return view('providers.index', compact(['providers']));
}
public function create()
{
return view('providers.create');
}
public function store(Request $request)
{
$request->validate([
'provider_name' => 'required|string|min:2|max:255'
]);
Providers::create([
'name' => $request->provider_name
]);
Cache::forget('providers');
2022-03-05 16:58:25 +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)
{
$data = Providers::showServicesForProvider($provider->id);
2022-03-05 16:58:25 +01:00
return view('providers.show', compact(['provider', 'data']));
}
public function destroy(Providers $provider)
{
$items = Providers::find($provider->id);
$items->delete();
Cache::forget('providers');
2022-03-05 16:58:25 +01:00
return redirect()->route('providers.index')
->with('success', 'Provider was deleted Successfully.');
}
}