shareit/app/Http/Controllers/HomeController.php
Bruno Fontes ea3ffaad39 Including occupied username and renaming DB field
Now it shows the username of who is using an item.
Item db field 'usedBy' was renamed to 'used_by' to keep consistence.
2018-09-14 12:52:07 -03:00

41 lines
882 B
PHP

<?php
namespace App\Http\Controllers;
use \App\User;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$items = User::find(\Auth::id())->items()->get();
foreach ($items as $item) {
if ($item->used_by) {
$users[$item->used_by] = User::find($item->used_by)->name;
if ($item->waiting_user_id) {
$users[$item->waiting_user_id] = User::find($item->waiting_user_id)->name;
}
}
}
return view('home', compact('items', 'users'));
}
}