Алина пре 4 година
родитељ
комит
aaaa529160

+ 39 - 0
app/Events/SendTweet.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Events;
+
+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 SendTweet
+{
+    use Dispatchable, InteractsWithSockets, SerializesModels;
+
+    public $user; 
+
+    /**
+     * Create a new event instance.
+     *
+     * @return void
+     */
+    public function __construct($user)
+    {
+        //
+        $this -> user = $user; 
+    }
+
+    /**
+     * Get the channels the event should broadcast on.
+     *
+     * @return \Illuminate\Broadcasting\Channel|array
+     */
+    public function broadcastOn()
+    {
+        return new PrivateChannel('channel-name');
+    }
+}

+ 9 - 1
app/Http/Controllers/Auth/RegisterController.php

@@ -9,6 +9,8 @@ use Illuminate\Foundation\Auth\RegistersUsers;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Validator;
 
+use App\Events\SendTweet;
+
 class RegisterController extends Controller
 {
     /*
@@ -64,10 +66,16 @@ class RegisterController extends Controller
      */
     protected function create(array $data)
     {
-        return User::create([
+        
+        $user = User::create([
             'name' => $data['name'],
             'email' => $data['email'],
             'password' => Hash::make($data['password']),
         ]);
+
+        event(new SendTweet($user));
+
+        return $user;
+
     }
 }

+ 41 - 0
app/Listeners/NotificationSendTweet.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Listeners;
+
+use App\Events\SendTweet;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\InteractsWithQueue;
+
+use Illuminate\Support\Facades\Mail;
+
+class NotificationSendTweet
+{
+    /**
+     * Create the event listener.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Handle the event.
+     *
+     * @param  SendTweet  $event
+     * @return void
+     */
+    public function handle(SendTweet $event)
+    {
+        $data = array('name' => $event -> user-> name,
+        'email' => $event -> user -> email,
+        'body' => 'Thank ypu for joining Twittor! i jope you will enjoy the loneliness!!');
+
+
+        Mail::send('email', $data, function($message) use ($data) {
+            $message -> to($data['email'])->subject('Thank you letter');
+            $message -> from('noreply@artisanweb.net');
+        });
+    }
+}

+ 2 - 2
app/Providers/EventServiceProvider.php

@@ -15,8 +15,8 @@ class EventServiceProvider extends ServiceProvider
      * @var array
      */
     protected $listen = [
-        Registered::class => [
-            SendEmailVerificationNotification::class,
+        'App\Events\SendTweet' => [
+            'App\Listeners\NotificationSendTweet',
         ],
     ];
 

+ 3 - 0
resources/views/email.blade.php

@@ -0,0 +1,3 @@
+Welcome! <strong> {{ $name }}</strong>
+
+<p>{{ $body }}</p>

+ 1 - 1
resources/views/home.blade.php

@@ -58,7 +58,7 @@
                         <div class=" card card-body">
                        
                             <h5 class="card-title"> {{ $message->title }} </h5>
-                            <h6 class="card-subtitle mb-2 text-muted"> {{ $message -> user-> name}} </h6>
+                            <h6 class="card-subtitle mb-2 text-muted">  {{ $message -> user-> name}} </h6>
                             <p class="card-text"> {{ $message -> content }} </p>
                             <p class="card-text text-muted">  {{ $message->created_at->diffForHumans() }} </p>
 

+ 1 - 1
resources/views/message.blade.php

@@ -21,7 +21,7 @@
 				</div>
 			</div>
 			<br>
-			<a  class="btn btn-primary float-right" href="/">return home</a>
+			<a  class="btn btn-primary float-right" href="{{ url('/') }}">return home</a>
 		</div>
 
 	</div>

+ 1 - 1
routes/web.php

@@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Route;
 
 use App\Http\Controllers\HController;
 use App\Http\Controllers\MessageController;
-
+use App\Events\SendTweet;
 
 Route::post('/create', [ MessageController::class, 'create' ]);