* change layout * change layout * #22 - wip * wip * wip * #22 - wip * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - added some tests * #22 - wip * #22 - wip * #22 - fix * #41 - wip * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #41 - wip * #41 - wip * #49 - laravel 9 * #41 - wip * #41 - fix * #41 - fix * Apply suggestions from code review Co-authored-by: Jacek Sawoszczuk <jacek.sawoszczuk@gmail.com> * #41 - cr fix * #41 - cr fix Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> Co-authored-by: Jacek Sawoszczuk <jacek.sawoszczuk@gmail.com>
		
			
				
	
	
		
			73 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace Toby\Domain\Notifications;
 | 
						|
 | 
						|
use Illuminate\Bus\Queueable;
 | 
						|
use Illuminate\Notifications\Messages\MailMessage;
 | 
						|
use Illuminate\Notifications\Notification;
 | 
						|
use InvalidArgumentException;
 | 
						|
use Toby\Eloquent\Models\VacationRequest;
 | 
						|
 | 
						|
class VacationRequestCreatedNotification extends Notification
 | 
						|
{
 | 
						|
    use Queueable;
 | 
						|
 | 
						|
    public function __construct(
 | 
						|
        protected VacationRequest $vacationRequest,
 | 
						|
    ) {
 | 
						|
    }
 | 
						|
 | 
						|
    public function via(): array
 | 
						|
    {
 | 
						|
        return ["mail"];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @throws InvalidArgumentException
 | 
						|
     */
 | 
						|
    public function toMail(): MailMessage
 | 
						|
    {
 | 
						|
        $url = route(
 | 
						|
            "vacation.requests.show",
 | 
						|
            [
 | 
						|
                "vacationRequest" => $this->vacationRequest,
 | 
						|
            ],
 | 
						|
        );
 | 
						|
        return $this->buildMailMessage($url);
 | 
						|
    }
 | 
						|
 | 
						|
    protected function buildMailMessage(string $url): MailMessage
 | 
						|
    {
 | 
						|
        $user = $this->vacationRequest->user->first_name;
 | 
						|
        $title = $this->vacationRequest->name;
 | 
						|
        $type = $this->vacationRequest->type->label();
 | 
						|
        $from = $this->vacationRequest->from->toDisplayDate();
 | 
						|
        $to = $this->vacationRequest->to->toDisplayDate();
 | 
						|
        $days = $this->vacationRequest->vacations()->count();
 | 
						|
        $appName = config("app.name");
 | 
						|
 | 
						|
        return (new MailMessage())
 | 
						|
            ->greeting(__("Hi :user!", [
 | 
						|
                "user" => $user,
 | 
						|
            ]))
 | 
						|
            ->subject(__("Vacation request :title has been created", [
 | 
						|
                "title" => $title,
 | 
						|
            ]))
 | 
						|
            ->line(__("The vacation request :title has been created correctly in the :appName.", [
 | 
						|
                "title" => $title,
 | 
						|
                "appName" => $appName,
 | 
						|
            ]))
 | 
						|
            ->line(__("Vacation type: :type", [
 | 
						|
                "type" => $type,
 | 
						|
            ]))
 | 
						|
            ->line(__("From :from to :to (number of days: :days)", [
 | 
						|
                "from" => $from,
 | 
						|
                "to" => $to,
 | 
						|
                "days" => $days,
 | 
						|
            ]))
 | 
						|
            ->action(__("Click here for details"), $url);
 | 
						|
    }
 | 
						|
}
 |