mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-23 20:10:52 +00:00
Including Alert me!
This commit is contained in:
parent
c4bd6a8a1a
commit
a173e3923a
28
app/Http/Controllers/AlertController.php
Normal file
28
app/Http/Controllers/AlertController.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use \App\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AlertController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
$item = User::find(\Auth::id())->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');
|
||||
}
|
||||
}
|
@ -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'));
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
38
app/Mail/ItemAvailable.php
Normal file
38
app/Mail/ItemAvailable.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use \App\Item;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class ItemAvailable extends Mailable
|
||||
{
|
||||
public $item;
|
||||
public $username;
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($username, Item $item)
|
||||
{
|
||||
$this->item = $item;
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->subject($this->item->name . ' is available!')
|
||||
->markdown('emails.itemAvailable');
|
||||
}
|
||||
}
|
12
resources/views/emails/itemAvailable.blade.php
Normal file
12
resources/views/emails/itemAvailable.blade.php
Normal file
@ -0,0 +1,12 @@
|
||||
@component('mail::message')
|
||||
Hi, {{$username}},
|
||||
<br>
|
||||
<br>
|
||||
#Good news: {{$item->name}} is available!
|
||||
<br>
|
||||
The item <em>{{$item->name}} ({{$item->product->name}})</em> is now available on **Share It**.
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://shareit.brunofontes.net/home">Take it</a> before anyone else.
|
||||
|
||||
@endcomponent
|
@ -15,10 +15,21 @@
|
||||
<form action="/alert" method="POST">
|
||||
{{ csrf_field() }}
|
||||
<input type="hidden" name="item" value="{{$item->id}}">
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary">Alert me</button>
|
||||
@if ($item->waiting_user_id == \Auth::id())
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger">Cancel Alert</button>
|
||||
@elseif (!$item->waiting_user_id)
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary">Alert me</button>
|
||||
@endif
|
||||
</form>
|
||||
</span>
|
||||
<span class="float-right mr-3">
|
||||
<em>{{str_limit($users[$item->used_by], 15, '...')}} ({{$item->updated_at->diffForHumans()}})</em>
|
||||
<em>
|
||||
{{str_limit($users[$item->used_by], 15, '...')}}
|
||||
@if ($item->waiting_user_id && $item->waiting_user_id != \Auth::id())
|
||||
<strong>> {{str_limit($users[$item->waiting_user_id], 15, '...')}}</strong>
|
||||
@endif
|
||||
<small>({{$item->updated_at->diffForHumans()}})</small>
|
||||
</em>
|
||||
</span>
|
||||
@endif
|
@ -25,7 +25,10 @@ Route::post('/item', 'ItemController@store')->middleware('auth');
|
||||
Route::delete('/item', 'ItemController@delete')->middleware('auth');
|
||||
|
||||
Route::post('/take', 'TakeController@store')->middleware('auth');
|
||||
Route::post('/return', 'ReturnController@store')->middleware('auth');
|
||||
Route::delete('/take', 'TakeController@delete')->middleware('auth');
|
||||
|
||||
Route::post('/alert', 'AlertController@store')->middleware('auth');
|
||||
Route::delete('/alert', 'AlertController@delete')->middleware('auth');
|
||||
|
||||
Route::post('/user', 'UserController@store')->middleware('auth');
|
||||
Route::delete('/user', 'UserController@delete')->middleware('auth');
|
||||
|
Loading…
Reference in New Issue
Block a user