Laravel / PHP- 404路由返回的页面不存在

时间:2018-10-24 10:18:18

标签: php angular laravel routes

我正在使用Laravel / Angular应用程序,刚刚添加了一个功能,允许用户在通过临时付款提醒页面生成PDF信件/电子邮件时设置自定义收件人名称。

Angular函数在临时提示中定义为:

updatePreferredAddresseeDetails($event, payer) {
    console.log("updatePreferredAddresseeDetails() called ");
    console.log("$event: ", $event);
    console.log("taxpayer: ", payer);
    console.log("account.preferredAddressee: ", payer.preferredAddresseeName);

    //$event.currentTarget.cancelBubble = true;
    const contact = payer['contacts'][$event.currentTarget.selectedIndex]; /* Need to ensure contact is defined here, so it can be used below- currently null here */

    console.log("contact: ", contact);
    //const data = (<any>Object).assign({}, payer, { transactionContactId: contact.userId });
    //console.log("data: ", data);

    payer.loading = true;
    payer.originalAddresseeName = payer.addresseename;
    payer.originalAddresseeNamePdf = payer.addresseenamepdf;

    payer.ADDRESSEENAME = $event.contactPreferredName;
    payer.ADDRESSEENAMEPDF = $event.contactPreferredAddresseeName;
    /*contact.originalAddresseeName = payer.addresseename;
    contact.originalAddresseeNamePdf = payer.addresseenamepdf;

    contact.ADDRESSEENAME = $event.contactPreferredName;
    contact.ADDRESSEENAMEPDF = $event.contactPreferredAddresseeName; */

    console.log("payer.addresseename: ", payer.ADDRESSEENAME);
    console.log("payer.addresseenamepdf: ", payer.ADDRESSEENAMEPDF);
    //this.provService.updatePreferredAddresseeDetails(data).subscribe(
    this.provService.updateTransactionContact(contact).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;
        }
    );
}

在PHP控制器中,我已使用以下方法定义了函数:

public function updatePreferredAddresseeDetails(Request $request)
{
    try
    {
        DB::beginTransaction();

        $transactionContactId = $request->input('transactionContactId');
        $transactionItemId = $request->input('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); /*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, 
                    '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);
    }
}

routes/web.php文件中,我已将路由添加到prov组:

Route::group(['prefix' => 'prov'], function() {
    ...
    Route::post('/preferredAddressee', 'WebApi\ProvController@updatePreferredAddresseeDetails');
});

当前,当页面加载时,当我从选项卡中跳出时,我将值输入到我添加到表单中的字段中,以便能够设置/修改addresseenameaddresseenamepdf值这些字段,将调用此updatePreferredAddresseeDetails()函数,但是我在控制台中收到一条消息,提示:

  

POST ... 404(未找到)

     

无法解释的反应

,然后在网络->预览选项卡上显示以下消息:

  

您尝试访问的页面不存在。

这是为什么?我在这里的路由有什么问题?

1 个答案:

答案 0 :(得分:0)

事实证明,发生此问题的原因是,在service.ts文件中设置URL时,我错过了一些“父”路由...在更改该行之后

private preferredAddresseeDetailsUpdateUrl: string = BASE_URL + '/web-api/preferredAddressee';

private preferredAddresseeDetailsUpdateUrl: string = BASE_URL + '/web-api/t/prov/preferredAddressee';

然后正确地映射了路线,并且我不再遇到page cannot be found错误。