diff --git a/app/Http/Controllers/AlertController.php b/app/Http/Controllers/AlertController.php
new file mode 100644
index 0000000..a3eec18
--- /dev/null
+++ b/app/Http/Controllers/AlertController.php
@@ -0,0 +1,28 @@
+items()->find(request('item'));
+ $item->waiting_user_id = \Auth::id();
+ $item->timestamps = false;
+ $item->save();
+ return redirect('home');
+ }
+
+ public function delete(Request $request)
+ {
+ $item = User::find(\Auth::id())->items()->find(request('item'));
+ $item->waiting_user_id = null;
+ $item->timestamps = false;
+ $item->save();
+
+ return redirect('home');
+ }
+}
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 62e0460..b2f31b4 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -50,7 +50,7 @@ class HomeController extends Controller
}
if ($item->waiting_user_id && !isset($users[$item->waiting_user_id])) {
- $users[$item->waiting_user_id] = $this->findName($item, $item->waiting_user_id);
+ $users[$item->waiting_user_id] = $this->findName($item->users, $item->waiting_user_id);
}
}
return view('home', compact('items', 'users'));
diff --git a/app/Http/Controllers/TakeController.php b/app/Http/Controllers/TakeController.php
index 85d0b54..05ffec0 100644
--- a/app/Http/Controllers/TakeController.php
+++ b/app/Http/Controllers/TakeController.php
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use \App\Item;
use \App\User;
+use App\Mail\ItemAvailable;
use Illuminate\Http\Request;
class TakeController extends Controller
@@ -19,9 +20,19 @@ class TakeController extends Controller
public function delete(Request $request)
{
$item = User::find(\Auth::id())->items()->find(request('item'));
+ $waiting_id = $item->waiting_user_id;
$item->used_by = null;
+ $item->waiting_user_id = null;
$item->save();
+ //Send e-mail to waiting user
+ if ($waiting_id) {
+ $user = User::find($waiting_id);
+ \Mail::to($user)->send(
+ new ItemAvailable($user->name, $item)
+ );
+ }
+
return redirect('home');
}
}
diff --git a/app/Mail/ItemAvailable.php b/app/Mail/ItemAvailable.php
new file mode 100644
index 0000000..17450c4
--- /dev/null
+++ b/app/Mail/ItemAvailable.php
@@ -0,0 +1,38 @@
+item = $item;
+ $this->username = $username;
+ }
+
+ /**
+ * Build the message.
+ *
+ * @return $this
+ */
+ public function build()
+ {
+ return $this->subject($this->item->name . ' is available!')
+ ->markdown('emails.itemAvailable');
+ }
+}
diff --git a/resources/views/emails/itemAvailable.blade.php b/resources/views/emails/itemAvailable.blade.php
new file mode 100644
index 0000000..0e7d11e
--- /dev/null
+++ b/resources/views/emails/itemAvailable.blade.php
@@ -0,0 +1,12 @@
+@component('mail::message')
+Hi, {{$username}},
+
+
+#Good news: {{$item->name}} is available!
+
+The item {{$item->name}} ({{$item->product->name}}) is now available on **Share It**.
+
+
+Take it before anyone else.
+
+@endcomponent
diff --git a/resources/views/home/usedItem.blade.php b/resources/views/home/usedItem.blade.php
index e2b1baf..5a5b4c3 100644
--- a/resources/views/home/usedItem.blade.php
+++ b/resources/views/home/usedItem.blade.php
@@ -15,10 +15,21 @@