removed some .env-example duplication config

updated rate updated event
added listener to user home page
This commit is contained in:
Jack Goh
2018-08-16 17:08:15 +08:00
parent 330fd3336b
commit d295b5d9b4
11 changed files with 118 additions and 83 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\Rate;
class RateUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $rate;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Rate $rate)
{
$this->rate = $rate;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('rate-updated');
//return new PrivateChannel('rate-updated');
}
public function broadcastWith() {
return [
'rate' => $this->rate,
];
}
}
-61
View File
@@ -1,61 +0,0 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class RateUpdated extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Observers;
use App\Rate;
use App\User;
use App\Events\RateUpdated;
class RateObserver
{
/**
* Handle the rate "created" event.
*
* @param \App\Rate $rate
* @return void
*/
public function created(Rate $rate)
{
event(new RateUpdated($rate));
}
}
+3
View File
@@ -5,6 +5,8 @@ namespace App\Providers;
use Laravel\Dusk\DuskServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use App\Observers\RateObserver;
use App\Rate;
class AppServiceProvider extends ServiceProvider
@@ -21,6 +23,7 @@ class AppServiceProvider extends ServiceProvider
Schema::defaultStringLength(191);
}
*/
Rate::observe(RateObserver::class);
Schema::defaultStringLength(191);
}
@@ -16,6 +16,7 @@ class BroadcastServiceProvider extends ServiceProvider
{
//Broadcast::routes();
Broadcast::routes(["middleware" => ["auth:api"]]);
require base_path('routes/channels.php');
}
}