doufen5175 2018-10-24 10:18
浏览 169
已采纳

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

I'm working on a Laravel/ Angular application, and have just added a function to allow the user to set a custom addressee name when generating a PDF letter/ email via the provisional payment reminders page.

The Angular function is defined in provisional-reminders.ts with:

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;
        }
    );
}

In the PHP controller, I have defined the function with:

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);
    }
}

In the routes/web.php file, I have added the route to the prov group:

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

Currently, when the page loads, and I enter values into the fields that I have added to the form to be able to set/ amend the addresseename & addresseenamepdf values, when I tab out of those fields, this updatePreferredAddresseeDetails() function is called, but I get a message in the console that says:

POST ... 404 (Not Found)

unparsable response

and the Network-> Preview tab shows the message:

You've tried to access a page that doesn't exist.

Why is this? What am I doing wrong with the routing here?

  • 写回答

1条回答 默认 最新

  • dongwei4103 2018-10-24 14:42
    关注

    So it turns out this issue was happening because I had missed a couple of the 'parent' routes when setting the URL in the service.ts file... After changing that line from

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

    to

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

    the routes were then mapped correctly, and I no longer got the page cannot be found error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
  • ¥15 Mac(标签-IDE|关键词-File) idea
  • ¥15 潜在扩散模型的Unet特征提取
  • ¥15 iscsi服务无法访问,如何解决?
  • ¥15 感应式传感器制作的感应式讯响器