Search code examples
phplaravelxero-api

Method App\Http\Controllers\XeroController::data does not exist


Hello i am having xero API

i am trying to integrate it with my laravel project , i am getting above error I am using following laravel package for same.

github package link : https://github.com/webfox/laravel-xero-oauth2/

enter image description here

----------------routes-----------------

Route::get('/manage/xero', [XeroController::class, 'index'])->name('xero.auth.success');

Route::get('xero/auth/callback', [XeroController::class, 'data'])->name('xero.auth.callback');

---controller-----------------

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Webfox\Xero\OauthCredentialManager;

class XeroController extends Controller
{
    public function index(Request $request, OauthCredentialManager $xeroCredentials)
    {
        try {
            // Check if we've got any stored credentials
            if ($xeroCredentials->exists()) {
                /* 
                 * We have stored credentials so we can resolve the AccountingApi, 
                 * If we were sure we already had some stored credentials then we could just resolve this through the controller
                 * But since we use this route for the initial authentication we cannot be sure!
                 */
                $xero             = resolve(\XeroAPI\XeroPHP\Api\AccountingApi::class);
                $organisationName = $xero->getOrganisations($xeroCredentials->getTenantId())->getOrganisations()[0]->getName();
                $user             = $xeroCredentials->getUser();
                $username         = "{$user['given_name']} {$user['family_name']} ({$user['username']})";
            }
        } catch (\throwable $e) {
            // This can happen if the credentials have been revoked or there is an error with the organisation (e.g. it's expired)
            $error = $e->getMessage();
        }

        return view('xero', [
            'connected'        => $xeroCredentials->exists(),
            'error'            => $error ?? null,
            'organisationName' => $organisationName ?? null,
            'username'         => $username ?? null
        ]);
    }
}

Solution

  • Your xero/auth/callback route is routed to the XeroController::data() function, which does not exist.

    Looking at that package, it looks like it already registers a route for xero/auth/callback, pointing to the AuthorizationCallbackController in the package. I'm assuming you just need to remove your manually defined route.