50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\ProviderType;
|
|
use App\Http\Requests\StoreProviderRequest;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Response;
|
|
|
|
class ProviderController extends Controller
|
|
{
|
|
public function create(Request $request): Response
|
|
{
|
|
Organisation::findOrFail($request->route('organisation'));
|
|
|
|
return inertia('providers/Create', [
|
|
'providerTypes' => array_values(ProviderType::toArray()),
|
|
]);
|
|
}
|
|
|
|
public function store(StoreProviderRequest $request): RedirectResponse
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
|
|
$organisation->providers()->create([
|
|
'name' => $request->string('name')->toString(),
|
|
'type' => $request->enum('type', ProviderType::class),
|
|
'token' => $request->string('token')->toString(),
|
|
]);
|
|
|
|
return redirect()
|
|
->route('organisations.show', ['organisation' => $organisation->id])
|
|
->with('success', 'Server provider created.');
|
|
}
|
|
|
|
public function destroy(Request $request): RedirectResponse
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
$provider = $organisation->providers()->findOrFail($request->route('provider'));
|
|
|
|
$provider->delete();
|
|
|
|
return redirect()
|
|
->route('organisations.show', ['organisation' => $organisation->id])
|
|
->with('success', 'Server provider deleted.');
|
|
}
|
|
}
|