-
app/Providers/EventServiceProvider.php
Open in GitHubuse Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { protected $listen = [ 'App\Events\ContentCreated' => [ 'App\Listeners\NotifyMentionedUsers', ], ]; }
-
app/Http/Controllers/CommentController.php
Open in GitHubuse App\Comment; use App\Discussion; use App\Group; use Auth; use Illuminate\Http\Request; /** * Comments CRUD controller. */ class CommentController extends Controller { public function store(Request $request, Group $group, Discussion $discussion) { $comment = new \App\Comment(); $comment->body = $request->input('body'); $comment->user()->associate(\Auth::user()); event(new \App\Events\ContentCreated($comment)); } }
-
app/Listeners/NotifyMentionedUsers.php
Open in GitHubuse App\Events\ContentCreated; use Notification; class NotifyMentionedUsers { public function handle(ContentCreated $event) { $user = $comment->discussion->group->users->where('username', $username)->first(); if ($user) { Notification::send($user, new \App\Notifications\MentionedUser($comment, \Auth::user())); flash($user->name.' '.trans('messages.notified')); } } }