Fixes #4132 - associated accessory users

This commit is contained in:
snipe 2017-10-03 21:03:00 -07:00
parent eaf55f5e79
commit f66e222f3d
2 changed files with 12 additions and 7 deletions

View file

@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use App\Helpers\Helper;
use App\Models\Accessory;
use App\Http\Transformers\AccessoriesTransformer;
use App\Models\Company;
class AccessoriesController extends Controller
@ -128,9 +129,15 @@ class AccessoriesController extends Controller
public function checkedout($id)
{
$this->authorize('view', Accessory::class);
$accessory = Accessory::findOrFail($id)->with('users')->first();
$total = $accessory->users->count();
return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $total);
$accessory = Accessory::findOrFail($id);
if (!Company::isCurrentUserHasAccess($accessory)) {
return ['total' => 0, 'rows' => []];
}
$accessory_users = $accessory->users;
$total = $accessory_users->count();
return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory_users, $total);
}

View file

@ -59,14 +59,12 @@ class AccessoriesTransformer
}
public function transformCheckedoutAccessory (Accessory $accessory, $total)
public function transformCheckedoutAccessory ($accessory_users, $total)
{
$array = array();
foreach ($accessory->users as $user) {
foreach ($accessory_users as $user) {
$array[] = [
'assigned_pivot_id' => $user->pivot->id,
'id' => (int) $user->id,