-
app/Providers/EventServiceProvider.php
Open in GitHubuse App\Events\PackageCreated; use App\Listeners\SendNewPackageNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { protected $listen = [ PackageCreated::class => [SendNewPackageNotification::class], ]; }
-
app/Http/Controllers/App/PackageController.php
Open in GitHubuse App\Collaborator; use App\Events\PackageCreated; use App\Events\PackageUpdated; use App\Http\Controllers\Controller; use App\Http\Requests\PackageFormRequest; use App\Package; use App\Tag; use DateTime; use Facades\App\Repo; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; class PackageController extends Controller { public function store(PackageFormRequest $request) { $repo = Repo::fromRequest($request); $package = Package::withoutSyncingToSearch(function () use ($request, $repo) { $package = Package::create(array_merge( request()->only(['name', 'author_id', 'url', 'abstract', 'instructions']), [ 'composer_name' => $request->getComposerName(), 'repo_url' => $repo->url(), 'readme_source' => $repo->source(), 'readme_format' => $repo->readmeFormat(), 'submitter_id' => auth()->user()->id, 'readme' => $repo->readme(), 'latest_version' => $repo->latestReleaseVersion(), ] )); return $package; }); event(new PackageCreated($package)); } }
-
app/Events/PackageCreated.php
Open in GitHubuse App\Package; class PackageCreated { public function __construct(Package $package) { $this->package = $package; } }
-
app/Listeners/SendNewPackageNotification.php
Open in GitHubuse App\Events\PackageCreated; use App\Notifications\NewPackage; use App\Tighten; class SendNewPackageNotification { public function handle(PackageCreated $event) { (new Tighten)->notify(new NewPackage($event->package)); } }