mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 08:04:09 -08:00
Merge branch 'develop'
This commit is contained in:
commit
bf344e9322
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue