I have this in the Dashboard Screenshot of the Dashboard
I want that it shows how many Tickets are open / closed / all
How do I do this with this Database?Screenshot from SELECT * FROM tickets
How do I do this that every user see his own open / closed and all tickets?
Advertisement
Answer
Inside your blade.php file you could do:
{{ $tickets->where('status', 'Open')->count() }}
To use this you need to pass $tickets from your controller to your view. Here’s an example of what that might look:
public function DashboardController(){ $tickets = Ticket::get(); return view('yourviewname', compact('tickets'); }
What’s great about this solution is that you can display it the way you want using only 1 query:
{{ $tickets->where('status', 'Closed')->count() }} {{ $tickets->count() }}
Join some code next time 🙂
Update
If you are not passing any data to your view you can also use (where Ticket is your model name)
{{ Ticket::where('status', 'Open')->get()->count() }}