fixed the repeated notes on edit

This commit is contained in:
Kwesi Banson
2024-03-13 16:21:55 +00:00
parent acda110be1
commit 1a4a3acfda
2 changed files with 18 additions and 16 deletions

View File

@@ -15,7 +15,7 @@ use Carbon\Carbon;
class ClientsController extends Controller
{
{
/**
* Display a listing of the resource.
*
@@ -313,27 +313,21 @@ class ClientsController extends Controller
'notes_body' => 'required'
]);
$auth_user = session('current_user');
$notes_arr = [
'notes_body' => $request->notes_body,
'services' => implode(',', $request->services),
'auth_user_id' => $auth_user['id'],
'client_id' => $request->client_id
];
$note = Models\ClientNote::find($request->note_id);
$note->notes_body = $request->notes_body;
$note->services = implode(',', $request->services);
if ($request->has('highlight')) {
$notes_arr['highlight'] = 'YES';
$note->highlight = 'YES';
}
$result = $note->save();
//dd($notes_arr);
// change this to update
$result = Models\ClientNote::create($notes_arr);
$notes = Models\ClientNote::with('client_info', 'created_by_info')->find($result->id);
//todo : send emails
$notes = Models\ClientNote::with('client_info', 'created_by_info')->find($request->note_id);
//dispatch(new SendNewNotesEmailAlert($notes));
if ($result) {
$data = ['code' => 1, 'msg' => 'Notes successfully added'];
$data = ['code' => 1, 'msg' => 'Notes successfully updated'];
}
else{
$data = ['code' => 3, 'msg' => 'Your request could not be handled at this time'];