I am trying to add some new functionality to a Laravel application I've just started working on- I have never used Laravel before, and only used PHP very briefly while at university about 9/10 years ago.
I've added a couple of input fields to a form in a dialog that's displayed on one of the pages- when a value is entered/ changed in either of these fields, a request should be made to update the value of a field in one of the database tables.
I've set the (change) attribute of the fields to call the Angular function- updatePreferredAddresseeDetails($event, payer), and within that function, have added a call to the PHP function that should perform the request- this.provService.updatePreferredAddresseeDetails(payer).subscribe();.
Currently, when I make a change to one of these fields on the form, and tab out of them, I can see in the console debug that the Angular function is called, but then get an error that says:
POST http://... 404 Not Found
In the routes/web.php file, I added a new route for the request I want to make with:
Route::group(['prefix' => 'prov'], function() {
...
Route::post('preferredAddressee', 'WebApi\ProvController@updatePreferredAddresseeDetails');
});
The PHP function is defined with:
public function updatePreferredAddresseeDetails(Request $request)
{
try
{
DB::beginTransaction();
$transactionContactId = $request->input('transactionContactId');
$transactionItemId = $request->input('transactionItemId');
//dd("transactionItemId: ", $transactionItemId);
if ($transactionItem = transactionItem::find($transactionItemId))
{
$transaction = $transactionItem->transaction;
if (User::canAccessTransaction( auth()->user()->user, $transaction))
{
$transaction->savePropertyValueByPropertyTag('TRANSACTIONCONTACT', $transactionContactId);
$account = Account::find($transaction->accountId);
$account->savePropertyValueByPropertyTag('ADDRESSEENAME', $request->input('contactPreferredName'));
$account->savePropertyValueByPropertyTag('ADDRESSEENAMEPDF', $request->input('contactPreferredAddresseeName'));
$trasaction->save();
$account->save();
/*$newContact = User::find($transactionContactId); /*ERF(23/10/2018 @ 1450) shouldn't need this line, as it's not a new contact- just updating an
existing one*/
DB::commit();
return response()->json([
'success' => true,
'transactionItemId' => $transactionItem->transactionItemId,
'transactionId' => $transactionItem->transactionId,
'transactionContactId' => $transactionContactId, //ERF(18/10/2018 @ 1220) transactionContactId is not a property of transactionItem
'addresseeName' => $account->ADDRESSEENAME,
'addresseeNamePdf' => $account->ADDRESSEENAMEPDF,
//'transactionContactName' => $newContact,
//dd(response);
]);
}
dd("transactionItem: ", $transactionItem);
}
else
{
dd("transactionItem could not be found ");
}
}
catch(Excetpion $e)
{
dd("exception caught: ", $e);
}
}
Where I'm calling this function from the Angular, I have the code:
this.provService.updatePreferredAddresseeDetails(payer).subscribe(
(response:any) => {
payer.addresseename = response.addresseename;
payer.addresseenamepdf = response.addresseenamepdf;
const message = new Message();
message.type = MessageType.SUCCESS;
message.message = 'Preferred Addressee details have been updated. ';
this.messagingService.emitMessage(message);
payer.loading = false;
},
(error:any) => {
//reset the names back to what they were originally because saving failed
payer.addresseename = payer.originalAddresseeName;
const message = new Message();
message.type = MessageType.ERROR;
message.message = error.message || 'There was a problem updaing the preferred addressee details. If the problem persists, please contact us.';
this.messagingService.emitMessage(message);
payer.loading = false;
}
);
When it's called, the message There was a problem updating the preferred addressee details. If the problem persists, please contact us. is displayed int he browser, so this tells me that there's an error in the response returned by the PHP function, but I can't seem to work out what I'm doing wrong there...
In the browser console, under Network-> Preview, I get a page that says You've tried to access a page that doesn't exist.
Anyone have any suggestions?