2021-07-04 01:44:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Payment;
|
|
|
|
|
2022-01-02 12:32:57 +01:00
|
|
|
use App\Fee;
|
2021-07-04 01:44:41 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
2022-02-12 01:16:37 +01:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2021-07-04 01:44:41 +02:00
|
|
|
use Illuminate\Http\Request;
|
2022-02-12 01:16:37 +01:00
|
|
|
use Inertia\Response;
|
2021-07-04 01:44:41 +02:00
|
|
|
|
|
|
|
class SubscriptionController extends Controller
|
|
|
|
{
|
2022-02-12 01:16:37 +01:00
|
|
|
public function index(Request $request): Response
|
|
|
|
{
|
2021-07-04 01:44:41 +02:00
|
|
|
session()->put('menu', 'subscription');
|
|
|
|
session()->put('title', 'Beiträge');
|
|
|
|
|
2022-02-12 14:28:03 +01:00
|
|
|
return \Inertia::render('subscription/SubscriptionIndex', [
|
2021-07-04 01:44:41 +02:00
|
|
|
'data' => SubscriptionResource::collection(Subscription::get()),
|
2022-03-11 20:19:17 +01:00
|
|
|
'toolbar' => [['href' => route('subscription.create'), 'label' => 'Beitrag anlegen', 'color' => 'primary', 'icon' => 'plus']],
|
2021-07-04 01:44:41 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-02-12 01:16:37 +01:00
|
|
|
public function create(): Response
|
|
|
|
{
|
2021-07-04 01:44:41 +02:00
|
|
|
session()->put('menu', 'subscription');
|
|
|
|
session()->put('title', 'Beitrag erstellen');
|
|
|
|
|
2022-02-12 14:28:03 +01:00
|
|
|
return \Inertia::render('subscription/SubscriptionForm', [
|
2022-01-02 12:32:57 +01:00
|
|
|
'fees' => Fee::pluck('name', 'id'),
|
2021-07-04 01:44:41 +02:00
|
|
|
'mode' => 'create',
|
2022-03-11 20:19:17 +01:00
|
|
|
'data' => (object) [],
|
2021-07-04 01:44:41 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-02-12 01:16:37 +01:00
|
|
|
public function store(Request $request): RedirectResponse
|
|
|
|
{
|
2021-07-04 01:44:41 +02:00
|
|
|
Subscription::create($request->validate([
|
|
|
|
'name' => 'required|max:255',
|
|
|
|
'amount' => 'required|numeric',
|
|
|
|
'fee_id' => 'required|exists:fees,id',
|
|
|
|
]));
|
|
|
|
|
|
|
|
return redirect()->route('subscription.index');
|
|
|
|
}
|
|
|
|
|
2022-02-12 01:16:37 +01:00
|
|
|
public function edit(Subscription $subscription, Request $request): Response
|
|
|
|
{
|
2021-07-04 01:44:41 +02:00
|
|
|
session()->put('menu', 'subscription');
|
|
|
|
session()->put('title', "Beitrag {$subscription->name} bearbeiten");
|
|
|
|
|
2022-02-12 14:28:03 +01:00
|
|
|
return \Inertia::render('subscription/SubscriptionForm', [
|
2022-01-02 12:32:57 +01:00
|
|
|
'fees' => Fee::pluck('name', 'id'),
|
2021-07-04 01:44:41 +02:00
|
|
|
'mode' => 'edit',
|
|
|
|
'data' => new SubscriptionResource($subscription),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-02-12 01:16:37 +01:00
|
|
|
public function update(Subscription $subscription, Request $request): RedirectResponse
|
|
|
|
{
|
2021-07-04 01:44:41 +02:00
|
|
|
$subscription->update($request->validate([
|
|
|
|
'name' => 'required|max:255',
|
|
|
|
'amount' => 'required|numeric',
|
|
|
|
'fee_id' => 'required|exists:fees,id',
|
|
|
|
]));
|
|
|
|
|
|
|
|
return redirect()->route('subscription.index');
|
|
|
|
}
|
|
|
|
}
|