39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\SourceProviderType;
|
|
use App\Http\Requests\StoreSourceProviderRequest;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Response;
|
|
|
|
class SourceProviderController extends Controller
|
|
{
|
|
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.');
|
|
}
|
|
}
|