What event can I listen for in Laravel Spark for when a user signs up for a free TEAM trial?
To be clear, this is probably not the TeamSubscribed event because the team is not yet on a subscription. I am looking for when a trial is started- I need to run some code.
This does not seem very effective for all cases. In the future we may add more types of subscriptions and trials. So if I base it off of when the team is created, that may be unsafe.
Without asking you to spend too much time on this, how would I go about that? I know that I can fire an event anywhere and the listener will pick up on it, but I need it to be connected to the point of a free trial being registered, which is a Spark thing.
I am not new to Laravel, but I'm not too familiar with the events and listeners portion.
Yes, That is why I suggested listening for one of the initial events. That way you know its a new registration. The trick is to decide how you want to fire the event if it meets your qualifications. The event itself should be suited to executing small bits of code.
The only events that Spark for teams provides are listed in the docs. I think the applicable to you would be this event: Teams\Subscription\TeamSubscribed. You can create a simple Laravel listener which decides if the team is on a trial and then fires an event to run your code. If not, it just passes to next. You can use an event subscriber as well to fine grain the event handling. Also, Spark::trialDays() may help with the listener determination.
A sample listener:
<?php
namespace app\Listeners;
use App\User;
use App\Notifications\UserDidRegister;
use Laravel\Spark\Events\Subscription\UserSubscribed;
class CreatedNewUser
{
public $user;
/**
* Create the event listener.
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Handle the event.
*
* @param UserSubscribed $event
*/
public function handle(UserSubscribed $event)
{
$user = $event->user;
$user->notify(new UserDidRegister($user));
}
}