check if the event is future or ongoing to send email and notification on deletion
This commit is contained in:
1 parent
400d70ff7e
commit
6966027096
1 file changed
+18
-15
@@ -4,7 +4,6 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Events\EventParticipationCancelled;
|
use App\Events\EventParticipationCancelled;
|
||||||
use App\Mail\EventParticipationCancelledMail;
|
use App\Mail\EventParticipationCancelledMail;
|
||||||
use App\Mail\ValidateMail;
|
|
||||||
use App\Models\Events;
|
use App\Models\Events;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -12,6 +11,7 @@ use Illuminate\Http\JsonResponse;
|
|||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
|
||||||
class EventsController extends Controller
|
class EventsController extends Controller
|
||||||
@@ -89,6 +89,8 @@ class EventsController extends Controller
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$event = Events::with('tasks.users')->find($id);
|
$event = Events::with('tasks.users')->find($id);
|
||||||
|
Log::info($event);
|
||||||
|
Log::info($event->tasks);
|
||||||
|
|
||||||
if (!$event) {
|
if (!$event) {
|
||||||
return response()->json(['message' => 'Event not found'], 404);
|
return response()->json(['message' => 'Event not found'], 404);
|
||||||
@@ -98,21 +100,22 @@ class EventsController extends Controller
|
|||||||
return $task->users;
|
return $task->users;
|
||||||
})->unique('id');
|
})->unique('id');
|
||||||
|
|
||||||
foreach ($participants as $user) {
|
if (Carbon::now()->lessThanOrEqualTo($event->end)) {
|
||||||
broadcast(new EventParticipationCancelled(
|
foreach ($participants as $user) {
|
||||||
$user->id,
|
broadcast(new EventParticipationCancelled(
|
||||||
$event
|
$user->id,
|
||||||
));
|
$event
|
||||||
|
));
|
||||||
$data = [
|
|
||||||
'name' => $user->name,
|
|
||||||
'lastname' => $user->lastname,
|
|
||||||
'eventName' => $event->name,
|
|
||||||
'start' => $event->start,
|
|
||||||
'end' => $event->end,
|
|
||||||
];
|
|
||||||
Mail::to($user->email)->send(new EventParticipationCancelledMail($data));
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $user->name,
|
||||||
|
'lastname' => $user->lastname,
|
||||||
|
'eventName' => $event->name,
|
||||||
|
'start' => $event->start,
|
||||||
|
'end' => $event->end,
|
||||||
|
];
|
||||||
|
Mail::to($user->email)->send(new EventParticipationCancelledMail($data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$event->delete();
|
$event->delete();
|
||||||
|
|||||||
Reference in new issue
Block a user