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.

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

报告相同问题?

悬赏问题

  • ¥150 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装