Skip to main content

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

Read more here

Bottelet/DaybydayCRM

2311 stars
2 code files
View Bottelet/DaybydayCRM on GitHub

app/Observers/TaskObserver.php

Open in GitHub
// This observer class takes care of soft-deleting, force-deleting, and restoring related records.
 
class TaskObserver
{
private $relations;
 
public function __construct()
{
$this->relations = [
'comments',
'documents',
'appointments',
'activity',
];
}
 
public function deleted(Task $task)
{
foreach ($this->relations as $relation) {
$task->$relation()->delete();
}
}
 
public function restored(Task $task)
{
foreach ($this->relations as $relation) {
$task->$relation()->withTrashed()->restore();
}
}
 
public function forceDeleted(Task $task)
{
foreach ($this->relations as $relation) {
$task->$relation()->forceDelete();
}
}
}

app/Providers/AppServiceProvider.php

Open in GitHub
// All Observer classes are registered in AppServiceProvider, then they are automatically enabled.
 
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Client::observe(ClientObserver::class);
Task::observe(TaskObserver::class);
 
// ... other observers
}
}

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.