From a3fe6f719dcd449fbc54c003b9a1a9fce4808232 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Wed, 12 Sep 2018 21:25:48 -0300 Subject: [PATCH] Refactoring homeController code --- app/Http/Controllers/HomeController.php | 8 +------- resources/views/home.blade.php | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 01c8f4a..a4407f2 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -23,13 +23,7 @@ class HomeController extends Controller */ public function index() { - $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.*', 'products.name as pname') - ->orderBy('items.name') - ->get(); + $items = \App\User::find(\Auth::id())->items()->get(); return view('home', compact('items')); } } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index b46f3ff..5d17104 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -16,23 +16,29 @@

Your itens

@forelse ($items as $item) -
  • - {{$item->name}} ({{$item->pname}}) +
    +
  • + {{$item->name}} ({{$item->product->name}}) @if ($item->usedBy) @if ($item->usedBy == \Auth::id()) -
    - + + {{ csrf_field() }} + +
    + {{\Carbon\Carbon::parse($item->updated_at)->diffForHumans()}} @else - + @endif @else -
    - + + {{ csrf_field() }} + +
    @endif