Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 24
AppNotifications
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 24
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 via
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 toMail
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 18
 toDatabase
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Carbon\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
class AppNotifications extends Notification implements ShouldQueue
{
    use Queueable;
    protected  $appMessageArr;
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($appMessageArr)
    {
        $this->appMessageArr = $appMessageArr;
    }
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database','mail'];
    }
    
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        Log::info('Email notification is being sent.');
        $today = Carbon::now(config('settings.time_zone'))->format(config('settings.php_date_format'));
        
        if($this->appMessageArr[2] == null){
            $getUrl = 'home';
        }else{
            $contains = Str::contains($this->appMessageArr[2],'#');
            //check route contains # symbol for user request discussion      
            if($contains){
                $url_explode = explode('#',$this->appMessageArr[2]);
                $getUrl =  $url_explode[0];
            }else{
                $getUrl = $this->appMessageArr[2];
           
            }
        }
        $url = URL::temporarySignedRoute(
                    $getUrl,
                    now()->addDays(1));
        return (new MailMessage)
            ->subject($this->appMessageArr[0] .' '.$today)
            ->greeting($this->appMessageArr[0])
            ->line($this->appMessageArr[1])
            ->action('Notification Action', $url)
            ->line('Thank you for using our application!');
    }
    public function toDatabase($notifiable)
    {
        return [
            'notification' => $this->appMessageArr[0],
            'message' => $this->appMessageArr[1],
            'actionUrl' => $this->appMessageArr[2]
        ];
    }
    
}