From b41b9b45571d5bbc3baf0dd62bd8c18aaf4ec1ba Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Wed, 12 Sep 2018 18:24:56 -0300 Subject: [PATCH] Adding product name with the item name on the Home page --- app/Http/Controllers/HomeController.php | 4 +++- resources/views/home.blade.php | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 2d91ddb..01c8f4a 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -25,8 +25,10 @@ class HomeController extends Controller { $items = \DB::table('items') ->join('item_user', 'item_user.item_id', '=', 'items.id') + ->join('products', 'products.id', '=', 'items.id') ->where('item_user.user_id', \Auth::id()) - ->select('items.*') + ->select('items.*', 'products.name as pname') + ->orderBy('items.name') ->get(); return view('home', compact('items')); } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 99b1262..b46f3ff 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -17,13 +17,24 @@

Your itens

@forelse ($items as $item)
  • - {{$item->name}} - @if ($item->usedSince) -
    - In use by {{$item->usedBy}}, since {{$item->usedSince->diffForHumans()}} -
    + {{$item->name}} ({{$item->pname}}) + + @if ($item->usedBy) + @if ($item->usedBy == \Auth::id()) + +
    + +
    +
    + @else + + @endif @else - TAKE IT + +
    + +
    +
    @endif
  • @empty