Update to laravel 12, other changes.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
use App\Models\ClientCase;
|
||||
use App\Models\Contract;
|
||||
use Exception;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
@@ -121,26 +123,32 @@ public function updateContract(ClientCase $clientCase, String $uuid, Request $re
|
||||
}
|
||||
|
||||
public function storeActivity(ClientCase $clientCase, Request $request) {
|
||||
|
||||
$attributes = $request->validate([
|
||||
'due_date' => 'nullable|date',
|
||||
'amount' => 'nullable|decimal:0,4',
|
||||
'note' => 'string',
|
||||
'action_id' => 'exists:\App\Models\Action,id',
|
||||
'decision_id' => 'exists:\App\Models\Decision,id'
|
||||
]);
|
||||
|
||||
//Create activity
|
||||
$activity = $clientCase->activities()->create($attributes);
|
||||
|
||||
foreach ($activity->decision->events as $e) {
|
||||
$class = '\\App\\Events\\' . $e->name;
|
||||
event(new $class($clientCase));
|
||||
}
|
||||
|
||||
try {
|
||||
$attributes = $request->validate([
|
||||
'due_date' => 'nullable|date',
|
||||
'amount' => 'nullable|decimal:0,4',
|
||||
'note' => 'nullable|string',
|
||||
'action_id' => 'exists:\App\Models\Action,id',
|
||||
'decision_id' => 'exists:\App\Models\Decision,id'
|
||||
]);
|
||||
|
||||
|
||||
return to_route('clientCase.show', $clientCase);
|
||||
//Create activity
|
||||
$row = $clientCase->activities()->create($attributes);
|
||||
/*foreach ($activity->decision->events as $e) {
|
||||
$class = '\\App\\Events\\' . $e->name;
|
||||
event(new $class($clientCase));
|
||||
}*/
|
||||
|
||||
logger()->info('Activity successfully inserted', $attributes);
|
||||
return to_route('clientCase.show', $clientCase)->with('success', 'Successful created!');
|
||||
} catch (QueryException $e) {
|
||||
logger()->error('Database error occurred:', ['error' => $e->getMessage()]);
|
||||
return back()->with('error', 'Failed to insert activity. ' . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
logger()->error('An unexpected error occurred:', ['error' => $e->getMessage()]);
|
||||
// Return a generic error response
|
||||
return back()->with('error', 'An unexpected error occurred. Please try again later.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DecisionController 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(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -21,4 +21,31 @@ public function index(Request $request){
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function updateAction(int $id, Request $request) {
|
||||
|
||||
$row = \App\Models\Action::findOrFail($id);
|
||||
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'decisions' => 'nullable|array',
|
||||
'decisions.*.id' => 'required_with:decisions.*|integer|exists:decisions,id',
|
||||
'decisions.*.name' => 'required_with:decisions.*|string|max:50'
|
||||
]);
|
||||
|
||||
$decisionIds = collect($attributes['decisions'] ?? [])->pluck('id')->toArray();
|
||||
|
||||
\DB::transaction(function() use ($attributes, $decisionIds, $row) {
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag']
|
||||
]);
|
||||
|
||||
$row->decisions()->sync($decisionIds);
|
||||
});
|
||||
logger()->info('Model updated successfully', ['model_id' => $row->id]);
|
||||
return to_route('settings')->with('success', 'Update successful!');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user