mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-16 23:42:32 +01:00
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Providers;
|
|
use Illuminate\Http\Request;
|
|
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');
|
|
|
|
return redirect()->route('providers.index')
|
|
->with('success', 'Provider Created Successfully.');
|
|
}
|
|
|
|
public function show(Providers $provider)
|
|
{
|
|
$data = Providers::showServicesForProvider($provider->id);
|
|
|
|
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.');
|
|
}
|
|
|
|
return redirect()->route('providers.index')
|
|
->with('error', 'Provider was not deleted.');
|
|
|
|
}
|
|
|
|
}
|