|
- <?php
-
- namespace App\Http\Controllers\Locations;
-
- use App\Models\Location;
- use App\Models\Stock;
- use Framework\Routing\Router;
-
- class ShowLocationsController
- {
- public function handle(Router $router)
- {
- $locations = Location::all();
- $stock = Stock::all();
-
- $totalsByLocation = [];
-
- foreach ($stock as $row) {
- $totalsByLocation[$row->location_id] = ($totalsByLocation[$row->location_id] ?? 0) + $row->quantity;
- }
-
- foreach ($locations as $location) {
- $location->totalQuantity = $totalsByLocation[$location->id] ?? 0;
- $location->route = $router->route('view-location', ['location' => $location->id]);
- }
-
- return view('locations/index', [
- 'locations' => $locations,
- 'createAction' => $router->route('show-create-location-form'),
- 'canManage' => session()->has('user_id'),
- ]);
- }
- }
|