Adding product name with the item name on the Home page

This commit is contained in:
Bruno F. Fontes 2018-09-12 18:24:56 -03:00
parent 8c0e46538c
commit 9f67cbcbeb
Signed by: brunofontes
GPG Key ID: EE3447CE80048495
2 changed files with 20 additions and 7 deletions

View File

@ -25,8 +25,10 @@ class HomeController extends Controller
{ {
$items = \DB::table('items') $items = \DB::table('items')
->join('item_user', 'item_user.item_id', '=', 'items.id') ->join('item_user', 'item_user.item_id', '=', 'items.id')
->join('products', 'products.id', '=', 'items.id')
->where('item_user.user_id', \Auth::id()) ->where('item_user.user_id', \Auth::id())
->select('items.*') ->select('items.*', 'products.name as pname')
->orderBy('items.name')
->get(); ->get();
return view('home', compact('items')); return view('home', compact('items'));
} }

View File

@ -17,13 +17,24 @@
<h4>Your itens</h4> <h4>Your itens</h4>
@forelse ($items as $item) @forelse ($items as $item)
<li> <li>
{{$item->name}} <strong>{{$item->name}}</strong> ({{$item->pname}})
@if ($item->usedSince)
<div class="alert"> @if ($item->usedBy)
In use by {{$item->usedBy}}, since {{$item->usedSince->diffForHumans()}} @if ($item->usedBy == \Auth::id())
</div> <span class="float-right">
<form action="/item/{{$item->id}}" method="POST">
<button type="button" class="btn btn-danger" disabled>Return It</button>
</form>
</span>
@else
<div class="alert alert-danger" role="alert">In use by {{$item->usedBy}}, since {{$item->usedSince->diffForHumans()}}</div>
@endif
@else @else
<a href="">TAKE IT</a> <span class="float-right">
<form action="/item/{{$item->id}}" method="POST">
<button type="button" class="btn btn-success">Take It</button>
</form>
</span>
@endif @endif
</li> </li>
@empty @empty