phplaravelgoogle-ads-apilaravel-jetstream

Target class [GoogleAdsApiController] does not exist


I am trying to replicate the Google Ads API Laravel Sample app and port it to a Laravel Jetstream application.

I keep getting the following error: Target class [GoogleAdsApiController] does not exist.

enter image description here

GoogleAdsApiController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Google\Ads\GoogleAds\Lib\V15\GoogleAdsClient;
use Google\Ads\GoogleAds\Util\FieldMasks;
use Google\Ads\GoogleAds\Util\V15\ResourceNames;
use Google\Ads\GoogleAds\V15\Enums\CampaignStatusEnum\CampaignStatus;
use Google\Ads\GoogleAds\V15\Resources\Campaign;
use Google\Ads\GoogleAds\V15\Services\CampaignOperation;
use Google\Ads\GoogleAds\V15\Services\GoogleAdsRow;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\View\View;

class GoogleAdsApiController extends Controller
{
    private const REPORT_TYPE_TO_DEFAULT_SELECTED_FIELDS = [
        'campaign' => ['campaign.id', 'campaign.name', 'campaign.status'],
        'customer' => ['customer.id']
    ];

    private const RESULTS_LIMIT = 100;

 ...

Routes/Web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\GoogleAdsApiController;



Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
});

Route::post(
    'pause-campaign',
    'GoogleAdsApiController@pauseCampaignAction'
);
Route::match(
    ['get', 'post'],
    'show-report',
    'GoogleAdsApiController@showReportAction'
);

 Route::get('/', function () {
    return view('welcome');
});

Route::get('/main', function () {
    return view('main');
});

Any help is much appreciated


Solution

  • There are couple of ways to do this operation

    Option 1:

    If you've recently created the GoogleAdsApiController or made changes to your project's directory structure, it's a good idea to run the composer dump-autoload command to update the Composer autoloader

    Option 2

    You can use this code:

    Route::post('/pause-campaign', [GoogleAdsApiController::class, 'pauseCampaignAction']);
    Route::match(['get', 'post'], '/show-report', [GoogleAdsApiController::class, 'showReportAction']);
    

    Still, if you are facing an issue then try this one

    Route::post('/pause-campaign', [App\Http\Controllers\GoogleAdsApiController::class, 'pauseCampaignAction']);
    Route::match(['get', 'post'], '/show-report', [App\Http\Controllers\GoogleAdsApiController::class, 'showReportAction']);