mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-24 12:17:10 +00:00
Bruno Fontes
528d3b4caf
The TakeController was manually sending the email message as well as dealing with item return, so I moved the email message to it's own listener, I created an event for it and moved the return part to the item model.
35 lines
808 B
PHP
35 lines
808 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use \App\Item;
|
|
use \App\User;
|
|
use Illuminate\Http\Request;
|
|
use App\Events\ReturnItem;
|
|
|
|
class TakeController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
$item = User::loggedIn()->items()->find(request('item'));
|
|
if ($item->used_by) {
|
|
return back()->withErrors(
|
|
\Lang::getFromJson(
|
|
"This item is already taken"
|
|
)
|
|
);
|
|
}
|
|
$item->used_by = \Auth::id();
|
|
$item->save();
|
|
return redirect('home');
|
|
}
|
|
|
|
public function delete(Request $request)
|
|
{
|
|
$item = User::loggedIn()->items()->find(request('item'));
|
|
event(new ReturnItem($item));
|
|
$item->returnItem();
|
|
return redirect('home');
|
|
}
|
|
}
|