-
app/Events/JobApplicationReceivedEvent.php
Open in GitHubuse App\Models\JobApplication; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class JobApplicationReceivedEvent { use Dispatchable, InteractsWithSockets, SerializesModels; public $application; public function __construct(JobApplication $application) { $this->application = $application; } public function broadcastOn() { return new PrivateChannel('channel-name'); } }
-
app/Listeners/JobApplicationListener.php
Open in GitHubuse App\Events\JobApplicationReceivedEvent; use App\Notifications\JobApplicationReceivedNotification; use Illuminate\Contracts\Queue\ShouldQueue; class JobApplicationListener { public function __construct() { } public function handle(JobApplicationReceivedEvent $event) { $user = $event->application->job->user; $user->notify(new JobApplicationReceivedNotification($event->application)); } }
-
app/Providers/EventServiceProvider.php
Open in GitHubuse App\Events\JobApplicationReceivedEvent; use App\Listeners\JobApplicationListener; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], JobApplicationReceivedEvent::class => [ JobApplicationListener::class, ], ]; // ... }
-
app/Http/Controllers/Front/StoreJobApplicationController.php
Open in GitHubuse App\Events\JobApplicationReceivedEvent; use App\Http\Controllers\Controller; use App\Http\Requests\StoreJobApplicationRequest; use App\Models\Job; class StoreJobApplicationController extends Controller { public function store(StoreJobApplicationRequest $request, Job $job) { $validated = $request->validated(); $validated['resume'] = $request->file('resume')->store('resumes'); $validated['cover_letter'] = request('coverLetter'); $application = $job->applications()->create($validated); event(new JobApplicationReceivedEvent($application)); return redirect()->route('jobApplicationReceived', ['job' => $job]); } // ... }