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');
|
|
|
|
|
|
|
|
return \Inertia::render('subscription/Index', [
|
|
|
|
'data' => SubscriptionResource::collection(Subscription::get()),
|
|
|
|
'toolbar' => [ ['href' => route('subscription.create'), 'label' => 'Beitrag anlegen', 'color' => 'primary', 'icon' => 'plus'] ],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
return \Inertia::render('subscription/Form', [
|
2022-01-02 12:32:57 +01:00
|
|
|
'fees' => Fee::pluck('name', 'id'),
|
2021-07-04 01:44:41 +02:00
|
|
|
'mode' => 'create',
|
|
|
|
'data' => (object) []
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
return \Inertia::render('subscription/Form', [
|
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');
|
|
|
|
}
|
|
|
|
}
|