From 8ae1e92a633496307cf79ee6929ee2001fb89589 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Tue, 16 Oct 2018 15:15:05 -0300 Subject: [PATCH] Refreshing and Including number of used items on Title It was necessary to keep refreshing the page to check if an item was returned when we did not want to be alerted. So, now, the page refresh itself every 2 minutes (while I do not know how to use Laravel broadcasting) and the title shows the number of items in use (including when used by you). --- app/Http/Controllers/HomeController.php | 6 +++++- resources/views/home.blade.php | 7 +++++++ resources/views/layouts/app.blade.php | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 34a3737..e452cf5 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -28,7 +28,11 @@ class HomeController extends Controller { $items = User::loggedIn()->items()->with('users')->get(); + $numberOfUsedItems = 0; foreach ($items as $item) { + if (isset($item->used_by)) { + $numberOfUsedItems++; + } $this->getUsername($item->users, $item->used_by); $this->getUsername($item->users, $item->waiting_user_id); } @@ -39,7 +43,7 @@ class HomeController extends Controller return view( 'home', - ['products' => $products, 'users' => $this->activeUsers] + ['products' => $products, 'users' => $this->activeUsers, 'usedItems' => $numberOfUsedItems] ); } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index eb60121..b0276d1 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -1,6 +1,13 @@ @extends('layouts.app') @section('content') + + +
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 24752f6..97afb3e 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -8,7 +8,7 @@ - {{ config('app.name', 'Laravel') }} + {{ config('app.name', 'Laravel') }} {{ $usedItems ? "(${usedItems})" : '' }}