Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

LaravelDaily/Laravel-Support-Ticketing

294 stars
2 code files
View LaravelDaily/Laravel-Support-Ticketing on GitHub

app/Observers/TicketActionObserver.php

Open in GitHub
use App\Notifications\DataChangeEmailNotification;
use App\Notifications\AssignedTicketNotification;
use App\Ticket;
use Illuminate\Support\Facades\Notification;
 
class TicketActionObserver
{
public function created(Ticket $model)
{
$data = ['action' => 'New ticket has been created!', 'model_name' => 'Ticket', 'ticket' => $model];
$users = \App\User::whereHas('roles', function ($q) {
return $q->where('title', 'Admin');
})->get();
Notification::send($users, new DataChangeEmailNotification($data));
}
 
public function updated(Ticket $model)
{
if($model->isDirty('assigned_to_user_id'))
{
$user = $model->assigned_to_user;
if($user)
{
Notification::send($user, new AssignedTicketNotification($model));
}
}
}
}

app/Ticket.php

Open in GitHub
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
 
class Ticket extends Model implements HasMedia
{
//
public static function boot()
{
parent::boot();
 
Ticket::observe(new \App\Observers\TicketActionObserver);
//
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.