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