work in progress: predefinedmutations
This commit is contained in:
@@ -69,6 +69,7 @@ class LedgerController extends Controller
|
||||
|
||||
$ledger->load([
|
||||
'media',
|
||||
'predefinedMutations',
|
||||
'mutations' => function ($query) {
|
||||
$query->latest();
|
||||
},
|
||||
|
||||
@@ -44,8 +44,14 @@ class MutationController extends Controller
|
||||
$status = $request->user()->can('update', $ledger) ? 'approved' : 'pending';
|
||||
|
||||
$mutation = DB::transaction(function () use ($request, $ledger, $status) {
|
||||
$predefinedId = null;
|
||||
if ($request->filled('predefined_mutation_id')) {
|
||||
$predefinedId = \App\Models\PredefinedMutation::where('uuid', $request->input('predefined_mutation_id'))->value('id');
|
||||
}
|
||||
|
||||
$mutation = $ledger->mutations()->create([
|
||||
...$request->except(['media', 'type', 'status']),
|
||||
...$request->except(['media', 'type', 'status', 'predefined_mutation_id']),
|
||||
'predefined_mutation_id' => $predefinedId,
|
||||
'user_id' => $request->user()->id,
|
||||
'type' => $request->input('type', $request->input('amount') >= 0 ? 'addition' : 'subtraction'),
|
||||
'status' => $status,
|
||||
|
||||
@@ -29,6 +29,7 @@ class StoreMutationRequest extends FormRequest
|
||||
'description' => ['required', 'string'],
|
||||
'type' => ['nullable', 'string'],
|
||||
'status' => ['nullable', 'string'],
|
||||
'predefined_mutation_id' => ['nullable', 'exists:predefined_mutations,uuid'],
|
||||
'media' => ['nullable', 'array'],
|
||||
'media.*' => ['file', 'mimes:jpg,jpeg,png,gif,mp4,mov,avi,webm', 'max:20480'],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user