Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action Illuminate\Broadcasting\BroadcastController@authenticate not defined #3021

Closed
aimensasi opened this issue Dec 16, 2020 · 13 comments
Closed
Labels

Comments

@aimensasi
Copy link

Bug Description

Integrating Statamic into an existing Laravel project.

Setting up locally (Mac OS), everything works as expected. However, during installation of composer packages on a staging server running (CentOS 7), I start receiving this issue and was not able to complete the setup.

Action Illuminate\Broadcasting\BroadcastController@authenticate not defined

Not sure what statamic has to do with broadcasting. However, After changing the following code inside Statamic\Providers\BroadcastServiceProvider, everything started working as expected.

   public function boot() {
        $this->app->booted(function () {
            $variables = $this->enabled() ? $this->variables() : ['enabled' => false];
            Statamic::provideToScript(['broadcasting' => $variables]);
        });
    }

Changes to

   public function boot() {
        $this->app->booted(function () {
            $variables = ['enabled' => false];
            Statamic::provideToScript(['broadcasting' => $variables]);
        });
    }

How to Reproduce

Extra Detail

[2020-12-16 11:30:44] local.ERROR: Action Illuminate\Broadcasting\BroadcastController@authenticate not defined. {"exception":"[object] (InvalidArgumentException(code: 0): Action Illuminate\\Broadcasting\\BroadcastController@authenticate not defined. at /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:468)
[stacktrace]
#0 /var/www/myemcq.tth.asia/vendor/statamic/cms/src/Providers/BroadcastServiceProvider.php(42): Illuminate\\Routing\\UrlGenerator->action('Illuminate\\\\Broa...')
#1 /var/www/myemcq.tth.asia/vendor/statamic/cms/src/Providers/BroadcastServiceProvider.php(23): Statamic\\Providers\\BroadcastServiceProvider->authEndpoint()
#2 /var/www/myemcq.tth.asia/vendor/statamic/cms/src/Providers/BroadcastServiceProvider.php(14): Statamic\\Providers\\BroadcastServiceProvider->variables()
#3 /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(910): Statamic\\Providers\\BroadcastServiceProvider->Statamic\\Providers\\{closure}(Object(Illuminate\\Foundation\\Application))
#4 /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\\Foundation\\Application->fireAppCallbacks(Array)
#5 /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#6 /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(230): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#7 /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(152): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#8 /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(136): Illuminate\\Foundation\\Http\\Kernel->bootstrap()
#9 /var/www/myemcq.tth.asia/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#10 /var/www/myemcq.tth.asia/public/index.php(60): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#11 {main}
"}

Environment

Statamic 3.0.33 Pro
Laravel 8.16.1
PHP 7.4.13

Install method (choose one):

  • Existing Laravel app
@jasonvarga
Copy link
Member

Does vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastController.php exist on the server? Does it have an authenticate method?

@aimensasi
Copy link
Author

Sorry for the late replay, did not see your response.

Yes the controller exists and has an authenticate method.

<?php

namespace Illuminate\Broadcasting;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Broadcast;

class BroadcastController extends Controller
{
    /**
     * Authenticate the request for channel access.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function authenticate(Request $request)
    {
        if ($request->hasSession()) {
            $request->session()->reflash();
        }

        return Broadcast::auth($request);
    }
}

@duncanmcclean
Copy link
Member

In the providers array in config/app.php, is the Illuminate BroadcastServiceProvider in there?

@aimensasi
Copy link
Author

yes it is and FYI, I am using the broadcast service in the project with websockets

@aimensasi
Copy link
Author

This is what I have inside the broadcast service

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;

class BroadcastServiceProvider extends ServiceProvider {
	/**
	 * Bootstrap any application services.
	 *
	 * @return void
	 */
	public function boot() {
		Broadcast::routes();

		require base_path('routes/channels.php');
	}
}

@duncanmcclean
Copy link
Member

Okay! I'm not entirely sure what's causing the issue that you're running into. I would have presumed Statamic would just work out of the box with the broadcasting stuff.

Just one more thing: if you temporarily comment out your BroadcastServiceProvider in your app.php and just leave the Illuminate one in place, does it start to work, or is it just the same thing?

I'm basing that on the fact that the config/app.php file provided in the default statamic/statamic starter kit has the Illuminate one uncommented and the custom one commented out. See here.

It might be a good idea to wait for the Statamic Team to come back online after the new year to look into the issue. I'm stuck sadly, I don't know much about broadcasting and my Googling didn't really help at all 😂

@aimensasi
Copy link
Author

I actually have tried that, but it did not help. Thanks for your help. I hope to see a response from them soon.

@jasonvarga
Copy link
Member

Just to confirm, when I asked if the class existed, you're definitely checking on the server and not just in your local repository?

@jasonvarga
Copy link
Member

Oh I think it's some combination of the cached bootstrap files.

What commands do you run as part of your deployment script?

Deleting the files inside bootstrap/cache (except for .gitignore) on production should bring it back to life.

@aimensasi
Copy link
Author

May be it is because of the cache, because after upgrading to the latest version to get the fix for this. The issue started appearing on local too during running the caching command.

the command is php artisan optimize

@podcasthosting
Copy link

podcasthosting commented Jan 16, 2021

We have the same problem. We also use Websockets. The problem also only arises after running php artisan optimize or just php artisan route:cache. Emptying the bootstrap/cache directory or just deleting bootstrap/cache/routes-v7.php helps temporarily.

@AlexanderFalkenberg
Copy link

I have the same issue on production, when using php artisan route:cache.

jasonvarga added a commit that referenced this issue Mar 18, 2021
If you cache your routes, they get loaded after our broadcast service provider. Closes #3021
@jasonvarga
Copy link
Member

jasonvarga commented Mar 18, 2021

Fixed for 3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants