feat: Implement Mutations CRUD

This commit is contained in:
Daan Meijer
2026-06-15 00:34:58 +02:00
parent 4fe89f0600
commit 8f2cf8e642
4 changed files with 152 additions and 1 deletions
@@ -0,0 +1,78 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreMutationRequest;
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Models\Mutation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class MutationController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreMutationRequest $request, Dynamic $dynamic, Ledger $ledger)
{
DB::transaction(function () use ($request, $ledger) {
$ledger->mutations()->create([
...$request->validated(),
'user_id' => $request->user()->id,
]);
$ledger->increment('score', $request->validated('amount'));
});
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
}
/**
* Display the specified resource.
*/
public function show(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
//
}
}
@@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Ledger;
class StoreMutationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
$ledger = $this->route('ledger');
return $ledger && $this->user()->can('view', $ledger);
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
*/
public function rules(): array
{
return [
'amount' => ['required', 'integer'],
'description' => ['required', 'string'],
'type' => ['nullable', 'string'],
'status' => ['nullable', 'string'],
];
}
}