Merge branch 'develop'

This commit is contained in:
snipe 2017-10-03 21:03:19 -07:00
commit bf344e9322
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\Helpers\Helper;
use App\Models\Accessory; use App\Models\Accessory;
use App\Http\Transformers\AccessoriesTransformer; use App\Http\Transformers\AccessoriesTransformer;
use App\Models\Company;
class AccessoriesController extends Controller class AccessoriesController extends Controller
@ -128,9 +129,15 @@ class AccessoriesController extends Controller
public function checkedout($id) public function checkedout($id)
{ {
$this->authorize('view', Accessory::class); $this->authorize('view', Accessory::class);
$accessory = Accessory::findOrFail($id)->with('users')->first();
$total = $accessory->users->count(); $accessory = Accessory::findOrFail($id);
return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $total); 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(); $array = array();
foreach ($accessory->users as $user) { foreach ($accessory_users as $user) {
$array[] = [ $array[] = [
'assigned_pivot_id' => $user->pivot->id, 'assigned_pivot_id' => $user->pivot->id,
'id' => (int) $user->id, 'id' => (int) $user->id,