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

60 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers;
use App\Models\Providers;
use Illuminate\Http\Request;
2022-03-05 16:58:25 +01:00
use Illuminate\Support\Facades\Cache;
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)
{
if ($provider->delete()) {
Cache::forget('providers');
return redirect()->route('providers.index')
->with('success', 'Provider was deleted Successfully.');
}
2022-03-05 16:58:25 +01:00
return redirect()->route('providers.index')
->with('error', 'Provider was not deleted.');
}
}