diff --git a/app/Http/Controllers/AlertController.php b/app/Http/Controllers/AlertController.php index a3eec18..a3916b3 100644 --- a/app/Http/Controllers/AlertController.php +++ b/app/Http/Controllers/AlertController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use \App\User; +use \App\Mail\UserWaiting; use Illuminate\Http\Request; class AlertController extends Controller @@ -13,6 +14,13 @@ class AlertController extends Controller $item->waiting_user_id = \Auth::id(); $item->timestamps = false; $item->save(); + + $loggedUser = \Auth::user()->name; + $userWithItem = User::find($item->used_by); + \Mail::to($userWithItem)->send( + new UserWaiting($loggedUser, $userWithItem->name, $item) + ); + return redirect('home'); } diff --git a/app/Mail/UserWaiting.php b/app/Mail/UserWaiting.php new file mode 100644 index 0000000..2be9b38 --- /dev/null +++ b/app/Mail/UserWaiting.php @@ -0,0 +1,40 @@ +item = $item; + $this->waitingUser = $waitingUser; + $this->userWithItem = $userWithItem; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->subject($this->waitingUser . ' wants to use ' . $this->item->name) + ->markdown('emails.userWaiting'); + } +} diff --git a/resources/views/emails/userWaiting.blade.php b/resources/views/emails/userWaiting.blade.php new file mode 100644 index 0000000..eda97d8 --- /dev/null +++ b/resources/views/emails/userWaiting.blade.php @@ -0,0 +1,16 @@ +@component('mail::message') +Hello, {{$userWithItem}}, + +Are you still using {{$item->name}}? + +We just want to let you know that {{$waitingUser}} asked us to be alerted when this item were available. + +So, if you are not using it anymore, please go to our site and... + +@component('mail::button', ['url' => 'https://shareit.brunofontes.net/home']) +Return it! +@endcomponent + +Thanks,
+{{ config('app.name') }} +@endcomponent