wowowowowo
This commit is contained in:
@@ -4,13 +4,26 @@ 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'));
|
||||
@@ -35,4 +48,44 @@ class SourceProviderController extends Controller
|
||||
->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.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user