-
app/Providers/EventServiceProvider.php
Open in GitHubuse Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Event; class EventServiceProvider extends ServiceProvider { // protected $listen = [ 'App\Events\Projects\Created' => [ 'App\Listeners\Projects\LogProjectCreationActivity', ], // ]; // }
-
app/Events/Projects/Created.php
Open in GitHubuse App\Entities\Projects\Project; class Created { public $project; public function __construct(Project $project) { $this->project = $project; } }
-
app/Listeners/Projects/LogProjectCreationActivity.php
Open in GitHubuse App\Entities\Users\Activity; use App\Events\Projects\Created; class LogProjectCreationActivity { public function handle(Created $event) { $project = $event->project; $activityEntry = [ 'type' => 'project_created', 'parent_id' => null, 'user_id' => auth()->id(), 'object_id' => $project->id, 'object_type' => 'projects', ]; Activity::create($activityEntry); } }