92 lines
3.3 KiB
PHP
92 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\SourceProviderType;
|
|
use App\Http\Requests\StoreSourceProviderRequest;
|
|
use App\Http\Requests\UpdateSourceProviderRequest;
|
|
use App\Models\Organisation;
|
|
use App\Models\SourceProvider;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Response;
|
|
|
|
class SourceProviderController extends Controller
|
|
{
|
|
public function index(Request $request): Response
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
|
|
return inertia('source-providers/Index', [
|
|
'sourceProviders' => $organisation->sourceProviders()
|
|
->latest()
|
|
->get(),
|
|
]);
|
|
}
|
|
|
|
public function create(Request $request): Response
|
|
{
|
|
Organisation::findOrFail($request->route('organisation'));
|
|
|
|
return inertia('source-providers/Create', [
|
|
'sourceProviderTypes' => array_values(SourceProviderType::toArray()),
|
|
]);
|
|
}
|
|
|
|
public function store(StoreSourceProviderRequest $request): RedirectResponse
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
|
|
$organisation->sourceProviders()->create([
|
|
'name' => $request->string('name')->toString(),
|
|
'type' => $request->enum('type', SourceProviderType::class),
|
|
'url' => $request->filled('url') ? rtrim($request->string('url')->toString(), '/') : null,
|
|
'config' => [],
|
|
]);
|
|
|
|
return redirect()
|
|
->route('organisations.show', ['organisation' => $organisation->id])
|
|
->with('success', 'Source provider created.');
|
|
}
|
|
|
|
public function edit(Request $request): Response
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
$sourceProvider = $organisation->sourceProviders()->findOrFail($request->route('source_provider'));
|
|
|
|
return inertia('source-providers/Edit', [
|
|
'sourceProvider' => $sourceProvider,
|
|
'sourceProviderTypes' => array_values(SourceProviderType::toArray()),
|
|
]);
|
|
}
|
|
|
|
public function update(UpdateSourceProviderRequest $request): RedirectResponse
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
/** @var SourceProvider $sourceProvider */
|
|
$sourceProvider = $organisation->sourceProviders()->findOrFail($request->route('source_provider'));
|
|
|
|
$sourceProvider->update([
|
|
'name' => $request->string('name')->toString(),
|
|
'type' => $request->enum('type', SourceProviderType::class),
|
|
'url' => $request->filled('url') ? rtrim($request->string('url')->toString(), '/') : null,
|
|
]);
|
|
|
|
return redirect()
|
|
->route('organisations.show', ['organisation' => $organisation->id])
|
|
->with('success', 'Source provider updated.');
|
|
}
|
|
|
|
public function destroy(Request $request): RedirectResponse
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
$sourceProvider = $organisation->sourceProviders()->findOrFail($request->route('source_provider'));
|
|
|
|
$sourceProvider->delete();
|
|
|
|
return redirect()
|
|
->route('organisations.show', ['organisation' => $organisation->id])
|
|
->with('success', 'Source provider deleted.');
|
|
}
|
|
}
|