简体   繁体   English

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

[英]Laravel/ PHP- 404 route returns page that doesn't exist

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

The Angular function is defined in provisional-reminders.ts with: 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;
        }
    );
}

In the PHP controller, I have defined the function with: 在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);
    }
}

In the routes/web.php file, I have added the route to the prov group: routes/web.php文件中,我已将路由添加到prov组:

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: 当前,当页面加载时,我在添加到表单中的字段中输入值以能够设置/修改addresseenameaddresseenamepdf值,当我从这些字段中跳出时,将调用此updatePreferredAddresseeDetails()函数,但我在控制台中收到一条消息,内容为:

POST ... 404 (Not Found) POST ... 404(未找到)

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? 我在这里的路由做错了什么?

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 事实证明,发生此问题是因为在service.ts文件中设置URL时,我错过了一些“父”路由service.ts

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. 然后正确地映射了路线,并且我再也找不到该page cannot be found错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM