Closed thomas4Bitcraft closed 3 weeks ago
Is this app using the new Laravel 11 skeleton, or is it using the old one? The easiest way is to check if your bootstrap/app.php
file contains Application::configure()
.
If you are using the new app skeleton, it looks like you're doing everything correctly. Can you share the contents of your bootstrap/app.php
and app/Providers/AppServiceProvider.php
🤔
If you're not using the new app skeleton, I think it's not working because you've added the $listen
property to the AppServiceProvider
, instead of the EventServiceProvider
.
@duncanmcclean Yes I'm using the new app.php:
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Sentry\Laravel\Integration;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'/generate/*',
'/!/forms/*',
]);
$middleware->append([
\App\Http\Middleware\LocaleMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
Integration::handles($exceptions);
})->create();
And set the $listen
poperty in the AppServiceProvider.php
<?php
namespace App\Providers;
use Bitcraft\FormWebhook\FormSaving;
use Bitcraft\FormWebhook\FormSubmission;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Statamic\Events\SubmissionCreated;
use Statamic\Events\SubmissionSaving;
use Statamic\Facades\Collection;
use Statamic\Statamic;
use Stillat\Relationships\Support\Facades\Relate;
class AppServiceProvider extends ServiceProvider
{
protected $listen = [
SubmissionSaving::class => [FormSaving::class],
SubmissionCreated::class => [FormSubmission::class],
];
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
if (env('APP_ENV') !== 'local') {
URL::forceScheme('https');
}
Relate::manyToMany(
'videolearnings.videos',
'videos.video_learning'
);
Collection::computed('posts', 'category_slug', function ($entry, $value) {
return $entry->category?->slug();
});
Statamic::vite('app', [
'resources/css/cp.css',
'resources/js/cp.js',
]);
}
}
You don't need to manually register event listeners in service providers anymore, as long as they live in app/Listeners
.
Have you imported the SubmissionSaving
event in your listener classes?
use Statamic\Events\SubmissionSaving;
In fact, looking at the code you provided, the events you had imported in your AppServiceProvider
were events belonging to a third-party addon, not Statamic.
Make sure you're importing the correct events.
Only the listeners itself are imported from an addon I wrote. The Events itself are imported from Statamic\Events\SubmissionSaving
.
This is the class for the Event Listener:
<?php
namespace Bitcraft\FormWebhook;
use Statamic\Events\SubmissionSaving;
class FormSaving
{
/**
* @param SubmissionSaving $event
* @return void
*/
public function handle(SubmissionSaving $event)
{
dd("asd");
}
}
I added the Listeners to App/Listeners
now and it works - weird that it does not when defining them manually
Ohhh, it's inside an addon.
Listeners inside addons aren't automatically registered yet, you need to register them manually as per the addon docs.
It's coming soon though: #10911
Bug description
I wanted to use the two Event Listeners, but they are not triggering.
How to reproduce
Here is the implementation:
When I send a POST request to
http://<domain>/!/forms/<form_handle>
this is not triggeredLogs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
No response