email notifications

This commit is contained in:
StudioTem committed 2023-03-30 09:35:26 +02:00
1 parent 850b400a8c
commit d825605a99
8 files changed
+181 -1

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Events;
use App\Models\SubTask;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class SubTaskCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $subtask;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Subtask $subtask)
{
$this->subtask = $subtask;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Events\SubTaskCreated;
use App\Http\Resources\BlockerResource;
use App\Http\Resources\SubTaskResource;
use App\Models\Attachment;
@@ -0,0 +1,34 @@
<?php
namespace App\Listeners;
use App\Events\SubTaskCreated;
use App\Mail\NewTask;
use App\Mail\PasswordReset;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Mail;
class SendNewTaskEmailNotification implements ShouldQueue
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\SubTaskCreated $event
* @return void
*/
public function handle(SubTaskCreated $event)
{
//Mail::to( $event->subtask->user->email )->send( new NewTask( $event->subtask ) );
}
}
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace App\Mail;
use App\Models\SubTask;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class NewTask extends Mailable
{
use Queueable, SerializesModels;
public $subtask;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Subtask $subtask)
{
$this->subtask = $subtask;
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: 'New Task',
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
view: 'emails.task.new_task_created',
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
namespace App\Observers;
use App\Events\SubTaskCreated;
use App\Models\SubTask;
class SubTaskObserver
@@ -14,7 +15,7 @@ class SubTaskObserver
*/
public function created(SubTask $subTask)
{
//
SubTaskCreated::dispatch($subTask);
}
public function updating(SubTask $subTask)
@@ -2,6 +2,8 @@
namespace App\Providers;
use App\Events\SubTaskCreated;
use App\Listeners\SendNewTaskEmailNotification;
use App\Models\MasterTask;
use App\Models\SubTask;
use App\Observers\MasterTaskObserver;
@@ -22,6 +24,10 @@ class EventServiceProvider extends ServiceProvider
Registered::class => [
SendEmailVerificationNotification::class,
],
SubTaskCreated::class => [
SendNewTaskEmailNotification::class,
//LogEvent::class,
],
];
/**
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
};
@@ -0,0 +1 @@
New task created: {{ $subtask->mastertask->title }}