More type-hinting

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-05 07:07:20 +01:00
parent 0d6fd2643d
commit 1d65781d8d
29 changed files with 245 additions and 412 deletions

View file

@ -3,10 +3,13 @@
namespace App\Helpers;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Response;
use Illuminate\Http\RedirectResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
class StorageHelper
{
public static function downloader($filename, $disk = 'default')
public static function downloader($filename, $disk = 'default') : BinaryFileResponse | RedirectResponse | StreamedResponse
{
if ($disk == 'default') {
$disk = config('filesystems.default');

View file

@ -16,6 +16,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
class AccessoriesController extends Controller
{
/**

View file

@ -4,28 +4,15 @@ namespace App\Http\Controllers\Api;
use App\Helpers\StorageHelper;
use Illuminate\Support\Facades\Storage;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Gate;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Actionlog;
use \Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Requests\UploadFileRequest;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
use Input;
use Paginator;
use Slack;
use Str;
use TCPDF;
use Validator;
use Route;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
/**
@ -44,12 +31,10 @@ class AssetFilesController extends Controller
*
* @param \App\Http\Requests\UploadFileRequest $request
* @param int $assetId
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
* @since [v6.0]
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
*/
public function store(UploadFileRequest $request, $assetId = null)
public function store(UploadFileRequest $request, $assetId = null) : JsonResponse
{
// Start by checking if the asset being acted upon exists
if (! $asset = Asset::find($assetId)) {
@ -84,12 +69,10 @@ class AssetFilesController extends Controller
* List the files for an asset.
*
* @param int $assetId
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
* @since [v6.0]
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
*/
public function list($assetId = null)
public function list($assetId = null) : JsonResponse
{
// Start by checking if the asset being acted upon exists
if (! $asset = Asset::find($assetId)) {
@ -128,7 +111,7 @@ class AssetFilesController extends Controller
* @since [v6.0]
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
*/
public function show($assetId = null, $fileId = null)
public function show($assetId = null, $fileId = null) : JsonResponse | StreamedResponse | Storage | StorageHelper | BinaryFileResponse
{
// Start by checking if the asset being acted upon exists
if (! $asset = Asset::find($assetId)) {
@ -146,7 +129,7 @@ class AssetFilesController extends Controller
// Form the full filename with path
$file = 'private_uploads/assets/'.$log->filename;
\Log::debug('Checking for '.$file);
Log::debug('Checking for '.$file);
if ($log->action_type == 'audit') {
$file = 'private_uploads/audits/'.$log->filename;
@ -178,12 +161,10 @@ class AssetFilesController extends Controller
*
* @param int $assetId
* @param int $fileId
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
* @since [v6.0]
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
*/
public function destroy($assetId = null, $fileId = null)
public function destroy($assetId = null, $fileId = null) : JsonResponse
{
// Start by checking if the asset being acted upon exists
if (! $asset = Asset::find($assetId)) {

View file

@ -9,9 +9,8 @@ use App\Models\Asset;
use App\Models\AssetMaintenance;
use App\Models\Company;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\JsonResponse;
/**
* This controller handles all actions related to Asset Maintenance for
@ -22,7 +21,6 @@ use Illuminate\Support\Facades\Input;
class AssetMaintenancesController extends Controller
{
/**
* Generates the JSON response for asset maintenances listing view.
*
@ -30,9 +28,8 @@ class AssetMaintenancesController extends Controller
* @author Vincent Sposato <vincent.sposato@gmail.com>
* @version v1.0
* @since [v1.8]
* @return string JSON
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Asset::class);
@ -120,9 +117,8 @@ class AssetMaintenancesController extends Controller
* @author Vincent Sposato <vincent.sposato@gmail.com>
* @version v1.0
* @since [v1.8]
* @return string JSON
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
$this->authorize('update', Asset::class);
// create a new model instance
@ -148,9 +144,8 @@ class AssetMaintenancesController extends Controller
* @param int $request
* @version v1.0
* @since [v4.0]
* @return string JSON
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse
{
$this->authorize('update', Asset::class);
@ -186,9 +181,8 @@ class AssetMaintenancesController extends Controller
* @param int $assetMaintenanceId
* @version v1.0
* @since [v4.0]
* @return string JSON
*/
public function destroy($assetMaintenanceId)
public function destroy($assetMaintenanceId) : JsonResponse
{
$this->authorize('update', Asset::class);
// Check if the asset maintenance exists
@ -212,9 +206,8 @@ class AssetMaintenancesController extends Controller
* @param int $assetMaintenanceId
* @version v1.0
* @since [v4.0]
* @return string JSON
*/
public function show($assetMaintenanceId)
public function show($assetMaintenanceId) : JsonResponse
{
$this->authorize('view', Asset::class);
$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);

View file

@ -11,9 +11,9 @@ use App\Http\Transformers\SelectlistTransformer;
use App\Models\Asset;
use App\Models\AssetModel;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\JsonResponse;
/**
* This class controls all actions related to asset models for
@ -29,9 +29,8 @@ class AssetModelsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', AssetModel::class);
$allowed_columns =
@ -117,10 +116,9 @@ class AssetModelsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
* @param \App\Http\Requests\StoreAssetModelRequest $request
*/
public function store(StoreAssetModelRequest $request)
public function store(StoreAssetModelRequest $request) : JsonResponse
{
$this->authorize('create', AssetModel::class);
$assetmodel = new AssetModel;
@ -141,9 +139,8 @@ class AssetModelsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', AssetModel::class);
$assetmodel = AssetModel::withCount('assets as assets_count')->findOrFail($id);
@ -157,9 +154,8 @@ class AssetModelsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function assets($id)
public function assets($id) : array
{
$this->authorize('view', AssetModel::class);
$assets = Asset::where('model_id', '=', $id)->get();
@ -177,7 +173,7 @@ class AssetModelsController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(StoreAssetModelRequest $request, $id)
public function update(StoreAssetModelRequest $request, $id) : JsonResponse
{
$this->authorize('update', AssetModel::class);
$assetmodel = AssetModel::findOrFail($id);
@ -210,9 +206,8 @@ class AssetModelsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', AssetModel::class);
$assetmodel = AssetModel::findOrFail($id);
@ -242,7 +237,7 @@ class AssetModelsController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$this->authorize('view.selectlists');

View file

@ -25,17 +25,12 @@ use App\Models\License;
use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use \Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Log;
use Paginator;
use Slack;
use Str;
use TCPDF;
use Validator;
use Illuminate\Support\Facades\Route;
@ -56,9 +51,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $assetId
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request, $action = null, $upcoming_status = null)
public function index(Request $request, $action = null, $upcoming_status = null) : JsonResponse | array
{
$filter_non_deprecable_assets = false;
@ -415,9 +409,8 @@ class AssetsController extends Controller
* @param string $tag
* @since [v4.2.1]
* @author [A. Gianotto] [<snipe@snipe.net>]
* @return \Illuminate\Http\JsonResponse
*/
public function showByTag(Request $request, $tag)
public function showByTag(Request $request, $tag) : JsonResponse | array
{
$this->authorize('index', Asset::class);
$assets = Asset::where('asset_tag', $tag)->with('assetstatus')->with('assignedTo');
@ -455,7 +448,7 @@ class AssetsController extends Controller
* @since [v4.2.1]
* @return \Illuminate\Http\JsonResponse
*/
public function showBySerial(Request $request, $serial)
public function showBySerial(Request $request, $serial) : JsonResponse | array
{
$this->authorize('index', Asset::class);
$assets = Asset::where('serial', $serial)->with('assetstatus')->with('assignedTo');
@ -482,19 +475,20 @@ class AssetsController extends Controller
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function show(Request $request, $id)
public function show(Request $request, $id) : JsonResponse | array
{
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()
->withCount('checkins as checkins_count', 'checkouts as checkouts_count', 'userRequests as user_requests_count')->findOrFail($id)) {
if ($asset = Asset::with('assetstatus')
->with('assignedTo')->withTrashed()
->withCount('checkins as checkins_count', 'checkouts as checkouts_count', 'userRequests as user_requests_count')->find($id)) {
$this->authorize('view', $asset);
return (new AssetsTransformer)->transformAsset($asset, $request->input('components') );
}
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
}
public function licenses(Request $request, $id)
public function licenses(Request $request, $id) : array
{
$this->authorize('view', Asset::class);
$this->authorize('view', License::class);
@ -511,9 +505,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
* @return \Illuminate\Http\JsonResponse
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$assets = Asset::select([
@ -660,9 +653,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param \App\Http\Requests\ImageUploadRequest $request
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Asset::class);
@ -756,9 +748,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $assetId
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Asset::class);
@ -785,9 +776,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $assetId
* @since [v5.1.18]
* @return \Illuminate\Http\JsonResponse
*/
public function restore(Request $request, $assetId = null)
public function restore(Request $request, $assetId = null) : JsonResponse
{
if ($asset = Asset::withTrashed()->find($assetId)) {
@ -815,9 +805,8 @@ class AssetsController extends Controller
* @author [N. Butler]
* @param string $tag
* @since [v6.0.5]
* @return \Illuminate\Http\JsonResponse
*/
public function checkoutByTag(AssetCheckoutRequest $request, $tag)
public function checkoutByTag(AssetCheckoutRequest $request, $tag) : JsonResponse
{
if ($asset = Asset::where('asset_tag', $tag)->first()) {
return $this->checkout($request, $asset->id);
@ -831,9 +820,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $assetId
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function checkout(AssetCheckoutRequest $request, $asset_id)
public function checkout(AssetCheckoutRequest $request, $asset_id) : JsonResponse
{
$this->authorize('checkout', Asset::class);
$asset = Asset::findOrFail($asset_id);
@ -909,9 +897,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $assetId
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function checkin(Request $request, $asset_id)
public function checkin(Request $request, $asset_id) : JsonResponse
{
$asset = Asset::with('model')->findOrFail($asset_id);
$this->authorize('checkin', $asset);
@ -993,9 +980,8 @@ class AssetsController extends Controller
*
* @author [A. Janes] [<ajanes@adagiohealth.org>]
* @since [v6.0]
* @return \Illuminate\Http\JsonResponse
*/
public function checkinByTag(Request $request, $tag = null)
public function checkinByTag(Request $request, $tag = null) : JsonResponse
{
$this->authorize('checkin', Asset::class);
if(null == $tag && null !== ($request->input('asset_tag'))) {
@ -1019,9 +1005,8 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $id
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function audit(Request $request)
public function audit(Request $request) : JsonResponse
{
$this->authorize('audit', Asset::class);
@ -1112,9 +1097,8 @@ class AssetsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function requestable(Request $request)
public function requestable(Request $request) : JsonResponse | array
{
$this->authorize('viewRequestable', Asset::class);

View file

@ -184,7 +184,7 @@ class CategoriesController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Category::class);
$category = Category::withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count')->findOrFail($id);
@ -207,7 +207,7 @@ class CategoriesController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request, $category_type = 'asset')
public function selectlist(Request $request, $category_type = 'asset') : array
{
$this->authorize('view.selectlists');
$categories = Category::select([

View file

@ -10,6 +10,7 @@ use App\Models\Company;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\JsonResponse;
class CompaniesController extends Controller
{
@ -18,9 +19,8 @@ class CompaniesController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Company::class);
@ -79,9 +79,8 @@ class CompaniesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ImageUploadRequest $request)
public function store(ImageUploadRequest $request) : JsonResponse
{
$this->authorize('create', Company::class);
$company = new Company;
@ -102,9 +101,8 @@ class CompaniesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', Company::class);
$company = Company::findOrFail($id);
@ -120,9 +118,8 @@ class CompaniesController extends Controller
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Company::class);
$company = Company::findOrFail($id);
@ -144,9 +141,8 @@ class CompaniesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Company::class);
$company = Company::findOrFail($id);
@ -169,7 +165,7 @@ class CompaniesController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$this->authorize('view.selectlists');
$companies = Company::select([

View file

@ -5,16 +5,17 @@ namespace App\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Transformers\ComponentsTransformer;
use App\Models\Company;
use App\Models\Component;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use App\Events\CheckoutableCheckedIn;
use App\Events\ComponentCheckedIn;
use App\Models\Asset;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
class ComponentsController extends Controller
{
@ -24,9 +25,8 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Component::class);
@ -116,9 +116,8 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ImageUploadRequest $request)
public function store(ImageUploadRequest $request) : JsonResponse
{
$this->authorize('create', Component::class);
$component = new Component;
@ -137,9 +136,8 @@ class ComponentsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', Component::class);
$component = Component::findOrFail($id);
@ -156,9 +154,8 @@ class ComponentsController extends Controller
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Component::class);
$component = Component::findOrFail($id);
@ -179,9 +176,8 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Component::class);
$component = Component::findOrFail($id);
@ -198,9 +194,8 @@ class ComponentsController extends Controller
* @since [v4.0]
* @param Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function getAssets(Request $request, $id)
public function getAssets(Request $request, $id) : array
{
$this->authorize('view', \App\Models\Asset::class);
@ -241,10 +236,8 @@ class ComponentsController extends Controller
* @since [v5.1.8]
* @param Request $request
* @param int $componentId
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function checkout(Request $request, $componentId)
public function checkout(Request $request, $componentId) : JsonResponse
{
// Check if the component exists
if (!$component = Component::find($componentId)) {
@ -275,7 +268,7 @@ class ComponentsController extends Controller
$component->assets()->attach($component->id, [
'component_id' => $component->id,
'created_at' => \Carbon::now(),
'created_at' => Carbon::now(),
'assigned_qty' => $request->get('assigned_qty', 1),
'user_id' => auth()->id(),
'asset_id' => $request->get('assigned_to'),
@ -297,12 +290,10 @@ class ComponentsController extends Controller
* @since [v5.1.8]
* @param Request $request
* @param $component_asset_id
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function checkin(Request $request, $component_asset_id)
public function checkin(Request $request, $component_asset_id) : JsonResponse
{
if ($component_assets = \DB::table('components_assets')->find($component_asset_id)) {
if ($component_assets = DB::table('components_assets')->find($component_asset_id)) {
if (is_null($component = Component::find($component_assets->component_id))) {
@ -315,7 +306,7 @@ class ComponentsController extends Controller
if ($max_to_checkin > 1) {
$validator = \Validator::make($request->all(), [
$validator = Validator::make($request->all(), [
"checkin_qty" => "required|numeric|between:1,$max_to_checkin"
]);
@ -334,19 +325,19 @@ class ComponentsController extends Controller
Log::debug($component_asset_id.' - '.$qty_remaining_in_checkout.' remaining in record '.$component_assets->id);
\DB::table('components_assets')->where('id',
DB::table('components_assets')->where('id',
$component_asset_id)->update(['assigned_qty' => $qty_remaining_in_checkout]);
// If the checked-in qty is exactly the same as the assigned_qty,
// we can simply delete the associated components_assets record
if ($qty_remaining_in_checkout == 0) {
\DB::table('components_assets')->where('id', '=', $component_asset_id)->delete();
DB::table('components_assets')->where('id', '=', $component_asset_id)->delete();
}
$asset = Asset::find($component_assets->asset_id);
event(new CheckoutableCheckedIn($component, $asset, auth()->user(), $request->input('note'), \Carbon::now()));
event(new CheckoutableCheckedIn($component, $asset, auth()->user(), $request->input('note'), Carbon::now()));
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/components/message.checkin.success')));

View file

@ -12,8 +12,8 @@ use App\Models\Consumable;
use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\JsonResponse;
class ConsumablesController extends Controller
{
@ -22,10 +22,8 @@ class ConsumablesController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : array
{
$this->authorize('index', Consumable::class);
@ -132,9 +130,8 @@ class ConsumablesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ImageUploadRequest $request)
public function store(ImageUploadRequest $request) : JsonResponse
{
$this->authorize('create', Consumable::class);
$consumable = new Consumable;
@ -153,9 +150,8 @@ class ConsumablesController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', Consumable::class);
$consumable = Consumable::with('users')->findOrFail($id);
@ -170,9 +166,8 @@ class ConsumablesController extends Controller
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Consumable::class);
$consumable = Consumable::findOrFail($id);
@ -192,9 +187,8 @@ class ConsumablesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Consumable::class);
$consumable = Consumable::findOrFail($id);
@ -211,9 +205,8 @@ class ConsumablesController extends Controller
* @see \App\Http\Controllers\Consumables\ConsumablesController::getView() method that returns the form.
* @since [v1.0]
* @param int $consumableId
* @return array
*/
public function getDataView($consumableId)
public function getDataView($consumableId) : array
{
$consumable = Consumable::with(['consumableAssignments'=> function ($query) {
$query->orderBy($query->getModel()->getTable().'.created_at', 'DESC');
@ -252,9 +245,8 @@ class ConsumablesController extends Controller
* @author [A. Gutierrez] [<andres@baller.tv>]
* @param int $id
* @since [v4.9.5]
* @return \Illuminate\Http\JsonResponse
*/
public function checkout(Request $request, $id)
public function checkout(Request $request, $id) : JsonResponse
{
// Check if the consumable exists
if (!$consumable = Consumable::with('users')->find($id)) {
@ -278,7 +270,6 @@ class ConsumablesController extends Controller
if (!$user = User::find($request->input('assigned_to'))) {
// Return error message
return response()->json(Helper::formatStandardApiResponse('error', null, 'No user found'));
Log::debug('No valid user');
}
// Update the consumable data
@ -304,7 +295,7 @@ class ConsumablesController extends Controller
*
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$consumables = Consumable::select([
'consumables.id',

View file

@ -8,7 +8,8 @@ use App\Http\Transformers\CustomFieldsTransformer;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use Illuminate\Http\Request;
use Validator;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\JsonResponse;
class CustomFieldsController extends Controller
{
@ -20,7 +21,7 @@ class CustomFieldsController extends Controller
* @since [v3.0]
* @return array
*/
public function index()
public function index() : array
{
$this->authorize('index', CustomField::class);
$fields = CustomField::get();
@ -33,9 +34,8 @@ class CustomFieldsController extends Controller
* @author [V. Cordes] [<volker@fdatek.de>]
* @param int $id
* @since [v4.1.10]
* @return \Illuminate\Contracts\View\View
*/
public function show($id)
public function show($id) : JsonResponse | array
{
$this->authorize('view', CustomField::class);
if ($field = CustomField::find($id)) {
@ -52,9 +52,8 @@ class CustomFieldsController extends Controller
* @since [v4.1.10]
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse
{
$this->authorize('update', CustomField::class);
$field = CustomField::findOrFail($id);
@ -86,9 +85,8 @@ class CustomFieldsController extends Controller
* @author [V. Cordes] [<volker@fdatek.de>]
* @since [v4.1.10]
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
$this->authorize('create', CustomField::class);
$field = new CustomField;
@ -136,7 +134,7 @@ class CustomFieldsController extends Controller
return $fieldset->fields()->sync($fields);
}
public function associate(Request $request, $field_id)
public function associate(Request $request, $field_id) : JsonResponse
{
$this->authorize('update', CustomFieldset::class);
@ -155,10 +153,9 @@ class CustomFieldsController extends Controller
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.update.success')));
}
public function disassociate(Request $request, $field_id)
public function disassociate(Request $request, $field_id) : JsonResponse
{
$this->authorize('update', CustomFieldset::class);
$field = CustomField::findOrFail($field_id);
$fieldset_id = $request->input('fieldset_id');
@ -179,9 +176,8 @@ class CustomFieldsController extends Controller
*
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
* @since [v1.8]
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($field_id)
public function destroy($field_id) : JsonResponse
{
$field = CustomField::findOrFail($field_id);

View file

@ -9,8 +9,7 @@ use App\Http\Transformers\CustomFieldsTransformer;
use App\Models\CustomFieldset;
use App\Models\CustomField;
use Illuminate\Http\Request;
use Redirect;
use View;
use Illuminate\Http\JsonResponse;
/**
* This controller handles all actions related to Custom Asset Fieldsets for
@ -30,9 +29,8 @@ class CustomFieldsetsController extends Controller
* @author [Josh Gibson]
* @param int $id
* @since [v1.8]
* @return \Illuminate\Contracts\View\View
*/
public function index()
public function index() : array
{
$this->authorize('index', CustomField::class);
$fieldsets = CustomFieldset::withCount('fields as fields_count', 'models as models_count')->get();
@ -46,9 +44,8 @@ class CustomFieldsetsController extends Controller
* @author [Josh Gibson]
* @param int $id
* @since [v1.8]
* @return \Illuminate\Contracts\View\View
*/
public function show($id)
public function show($id) : JsonResponse | array
{
$this->authorize('view', CustomField::class);
if ($fieldset = CustomFieldset::find($id)) {
@ -65,9 +62,8 @@ class CustomFieldsetsController extends Controller
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse
{
$this->authorize('update', CustomField::class);
$fieldset = CustomFieldset::findOrFail($id);
@ -86,9 +82,8 @@ class CustomFieldsetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
$this->authorize('create', CustomField::class);
$fieldset = new CustomFieldset;
@ -118,9 +113,8 @@ class CustomFieldsetsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', CustomField::class);
$fieldset = CustomFieldset::findOrFail($id);
@ -147,7 +141,7 @@ class CustomFieldsetsController extends Controller
* @param $fieldsetId
* @return string JSON
*/
public function fields($id)
public function fields($id) : array
{
$this->authorize('view', CustomField::class);
$set = CustomFieldset::findOrFail($id);
@ -164,14 +158,11 @@ class CustomFieldsetsController extends Controller
* @param $fieldsetId
* @return string JSON
*/
public function fieldsWithDefaultValues($fieldsetId, $modelId)
public function fieldsWithDefaultValues($fieldsetId, $modelId) : array
{
$this->authorize('view', CustomField::class);
$set = CustomFieldset::findOrFail($fieldsetId);
$fields = $set->fields;
return (new CustomFieldsTransformer)->transformCustomFieldsWithDefaultValues($fields, $modelId, $fields->count());
}
}

View file

@ -6,12 +6,11 @@ use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Transformers\DepartmentsTransformer;
use App\Http\Transformers\SelectlistTransformer;
use App\Models\Company;
use App\Models\Department;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\JsonResponse;
class DepartmentsController extends Controller
{
@ -20,9 +19,8 @@ class DepartmentsController extends Controller
*
* @author [Godfrey Martinez] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Department::class);
$allowed_columns = ['id', 'name', 'image', 'users_count'];
@ -91,9 +89,8 @@ class DepartmentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ImageUploadRequest $request)
public function store(ImageUploadRequest $request) : JsonResponse
{
$this->authorize('create', Department::class);
$department = new Department;
@ -116,13 +113,11 @@ class DepartmentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', Department::class);
$department = Department::findOrFail($id);
return (new DepartmentsTransformer)->transformDepartment($department);
}
@ -133,9 +128,8 @@ class DepartmentsController extends Controller
* @since [v5.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Department::class);
$department = Department::findOrFail($id);
@ -156,9 +150,8 @@ class DepartmentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $locationId
* @since [v4.0]
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$department = Department::findOrFail($id);
@ -180,7 +173,7 @@ class DepartmentsController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$this->authorize('view.selectlists');

View file

@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use App\Http\Transformers\DepreciationsTransformer;
use App\Models\Depreciation;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
class DepreciationsController extends Controller
{
@ -15,9 +16,8 @@ class DepreciationsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Depreciation::class);
$allowed_columns = ['id','name','months','depreciation_min','created_at'];
@ -48,9 +48,8 @@ class DepreciationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
$this->authorize('create', Depreciation::class);
$depreciation = new Depreciation;
@ -69,9 +68,8 @@ class DepreciationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : JsonResponse | array
{
$this->authorize('view', Depreciation::class);
$depreciation = Depreciation::findOrFail($id);
@ -86,9 +84,8 @@ class DepreciationsController extends Controller
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse
{
$this->authorize('update', Depreciation::class);
$depreciation = Depreciation::findOrFail($id);
@ -107,9 +104,8 @@ class DepreciationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Depreciation::class);
$depreciation = Depreciation::withCount('models as models_count')->findOrFail($id);

View file

@ -7,7 +7,7 @@ use App\Http\Controllers\Controller;
use App\Http\Transformers\GroupsTransformer;
use App\Models\Group;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\JsonResponse;
class GroupsController extends Controller
@ -17,9 +17,8 @@ class GroupsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('superadmin');
@ -56,9 +55,8 @@ class GroupsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
$this->authorize('superadmin');
$group = new Group;
@ -83,9 +81,8 @@ class GroupsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('superadmin');
$group = Group::findOrFail($id);
@ -99,9 +96,8 @@ class GroupsController extends Controller
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse
{
$this->authorize('superadmin');
$group = Group::findOrFail($id);
@ -122,9 +118,8 @@ class GroupsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('superadmin');
$group = Group::findOrFail($id);

View file

@ -17,15 +17,15 @@ use Illuminate\Support\Facades\Storage;
use League\Csv\Reader;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\JsonResponse;
class ImportController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
public function index() : JsonResponse | array
{
$this->authorize('import');
$imports = Import::latest()->get();
@ -37,9 +37,8 @@ class ImportController extends Controller
* Process and store a CSV upload file.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function store()
public function store() : JsonResponse
{
$this->authorize('import');
if (! config('app.lock_passwords')) {
@ -152,9 +151,8 @@ class ImportController extends Controller
* Processes the specified Import.
*
* @param int $import_id
* @return \Illuminate\Http\Response
*/
public function process(ItemImportRequest $request, $import_id)
public function process(ItemImportRequest $request, $import_id) : JsonResponse
{
$this->authorize('import');
@ -212,9 +210,8 @@ class ImportController extends Controller
* Remove the specified resource from storage.
*
* @param int $import_id
* @return \Illuminate\Http\Response
*/
public function destroy($import_id)
public function destroy($import_id) : JsonResponse
{
$this->authorize('create', Asset::class);
@ -231,6 +228,8 @@ class ImportController extends Controller
return response()->json(Helper::formatStandardApiResponse('warning', null, trans('admin/hardware/message.import.file_not_deleted_warning')));
}
}
return response()->json(Helper::formatStandardApiResponse('warning', null, trans('admin/hardware/message.import.file_not_deleted_warning')));
}
}

View file

@ -8,7 +8,7 @@ use App\Http\Transformers\LabelsTransformer;
use App\Models\Labels\Label;
use Illuminate\Http\Request;
use Illuminate\Support\ItemNotFoundException;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\JsonResponse;
class LabelsController extends Controller
{
@ -16,9 +16,8 @@ class LabelsController extends Controller
* Returns JSON listing of all labels.
*
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Label::class);
@ -50,9 +49,8 @@ class LabelsController extends Controller
*
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
* @param string $labelName
* @return \Illuminate\Http\JsonResponse
*/
public function show(string $labelName)
public function show(string $labelName) : JsonResponse | array
{
$labelName = str_replace('/', '\\', $labelName);
try {

View file

@ -9,7 +9,7 @@ use App\Models\Asset;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class LicenseSeatsController extends Controller
@ -19,11 +19,10 @@ class LicenseSeatsController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $licenseId
* @return \Illuminate\Http\Response
*/
public function index(Request $request, $licenseId)
public function index(Request $request, $licenseId) : JsonResponse | array
{
//
if ($license = License::find($licenseId)) {
$this->authorize('view', $license);
@ -64,11 +63,10 @@ class LicenseSeatsController extends Controller
*
* @param int $licenseId
* @param int $seatId
* @return \Illuminate\Http\Response
*/
public function show($licenseId, $seatId)
public function show($licenseId, $seatId) : JsonResponse | array
{
//
$this->authorize('view', License::class);
// sanity checks:
// 1. does the license seat exist?
@ -89,19 +87,18 @@ class LicenseSeatsController extends Controller
* @param \Illuminate\Http\Request $request
* @param int $licenseId
* @param int $seatId
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $licenseId, $seatId)
public function update(Request $request, $licenseId, $seatId) : JsonResponse | array
{
$this->authorize('checkout', License::class);
// sanity checks:
// 1. does the license seat exist?
if (! $licenseSeat = LicenseSeat::find($seatId)) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat not found'));
}
// 2. does the seat belong to the specified license?
if (! $license = $licenseSeat->license()->first() || $license->id != intval($licenseId)) {
$license = $licenseSeat->license()->first();
if (!$license || $license->id != intval($licenseId)) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat does not belong to the specified license'));
}

View file

@ -4,14 +4,12 @@ namespace App\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Transformers\LicenseSeatsTransformer;
use App\Http\Transformers\LicensesTransformer;
use App\Http\Transformers\SelectlistTransformer;
use App\Models\Company;
use App\Models\License;
use App\Models\LicenseSeat;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\JsonResponse;
class LicensesController extends Controller
{
@ -21,9 +19,8 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', License::class);
@ -156,11 +153,9 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
//
$this->authorize('create', License::class);
$license = new License;
$license->fill($request->all());
@ -177,9 +172,8 @@ class LicensesController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : JsonResponse | array
{
$this->authorize('view', License::class);
$license = License::withCount('freeSeats')->findOrFail($id);
@ -195,9 +189,8 @@ class LicensesController extends Controller
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse | array
{
//
$this->authorize('update', License::class);
@ -218,9 +211,8 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
//
$license = License::findOrFail($id);
@ -248,7 +240,7 @@ class LicensesController extends Controller
*
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$licenses = License::select([
'licenses.id',

View file

@ -11,6 +11,7 @@ use App\Models\Location;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Http\JsonResponse;
class LocationsController extends Controller
{
@ -21,7 +22,7 @@ class LocationsController extends Controller
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Location::class);
$allowed_columns = [
@ -138,9 +139,8 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ImageUploadRequest $request)
public function store(ImageUploadRequest $request) : JsonResponse
{
$this->authorize('create', Location::class);
$location = new Location;
@ -160,9 +160,8 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : JsonResponse | array
{
$this->authorize('view', Location::class);
$location = Location::with('parent', 'manager', 'children')
@ -199,9 +198,8 @@ class LocationsController extends Controller
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\JsonResponse
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Location::class);
$location = Location::findOrFail($id);
@ -230,9 +228,8 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Location::class);
$location = Location::withCount('assignedAssets as assigned_assets_count')
@ -280,7 +277,7 @@ class LocationsController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
// If a user is in the process of editing their profile, as determined by the referrer,
// then we check that they have permission to edit their own location.
@ -325,7 +322,6 @@ class LocationsController extends Controller
$paginated_results = new LengthAwarePaginator($locations_formatted->forPage($page, 500), $locations_formatted->count(), 500, $page, []);
//return [];
return (new SelectlistTransformer)->transformSelectlist($paginated_results);
}
}

View file

@ -10,8 +10,8 @@ use App\Models\Actionlog;
use App\Models\Manufacturer;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\JsonResponse;
class ManufacturersController extends Controller
{
@ -22,7 +22,7 @@ class ManufacturersController extends Controller
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Manufacturer::class);
$allowed_columns = ['id', 'name', 'url', 'support_url', 'support_email', 'warranty_lookup_url', 'support_phone', 'created_at', 'updated_at', 'image', 'assets_count', 'consumables_count', 'components_count', 'licenses_count'];
@ -83,9 +83,8 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ImageUploadRequest $request)
public function store(ImageUploadRequest $request) : JsonResponse
{
$this->authorize('create', Manufacturer::class);
$manufacturer = new Manufacturer;
@ -105,9 +104,8 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : JsonResponse | array
{
$this->authorize('view', Manufacturer::class);
$manufacturer = Manufacturer::withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count')->findOrFail($id);
@ -122,9 +120,8 @@ class ManufacturersController extends Controller
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Manufacturer::class);
$manufacturer = Manufacturer::findOrFail($id);
@ -144,9 +141,8 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Manufacturer::class);
$manufacturer = Manufacturer::findOrFail($id);
@ -167,10 +163,9 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v6.3.4]
* @param int $id
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function restore($id)
public function restore($id) : JsonResponse
{
$this->authorize('delete', Manufacturer::class);
@ -206,7 +201,7 @@ class ManufacturersController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$this->authorize('view.selectlists');

View file

@ -7,6 +7,8 @@ use App\Http\Controllers\Controller;
use App\Http\Transformers\PredefinedKitsTransformer;
use App\Models\PredefinedKit;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Transformers\SelectlistTransformer;
/**
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
@ -18,7 +20,7 @@ class PredefinedKitsController extends Controller
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', PredefinedKit::class);
$allowed_columns = ['id', 'name'];
@ -47,9 +49,8 @@ class PredefinedKitsController extends Controller
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
$this->authorize('create', PredefinedKit::class);
$kit = new PredefinedKit;
@ -66,9 +67,8 @@ class PredefinedKitsController extends Controller
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($id);
@ -81,9 +81,8 @@ class PredefinedKitsController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $id kit id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($id);
@ -100,9 +99,8 @@ class PredefinedKitsController extends Controller
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($id);
@ -123,7 +121,7 @@ class PredefinedKitsController extends Controller
*
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$kits = PredefinedKit::select([
'id',
@ -145,7 +143,7 @@ class PredefinedKitsController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function indexLicenses($kit_id)
public function indexLicenses($kit_id) : array
{
$this->authorize('view', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -160,7 +158,7 @@ class PredefinedKitsController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function storeLicense(Request $request, $kit_id)
public function storeLicense(Request $request, $kit_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
@ -186,9 +184,8 @@ class PredefinedKitsController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function updateLicense(Request $request, $kit_id, $license_id)
public function updateLicense(Request $request, $kit_id, $license_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -205,9 +202,8 @@ class PredefinedKitsController extends Controller
* Remove the specified resource from storage.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function detachLicense($kit_id, $license_id)
public function detachLicense($kit_id, $license_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -221,9 +217,8 @@ class PredefinedKitsController extends Controller
* Display the specified resource.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function indexModels($kit_id)
public function indexModels($kit_id) : array
{
$this->authorize('view', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -236,9 +231,8 @@ class PredefinedKitsController extends Controller
* Store the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function storeModel(Request $request, $kit_id)
public function storeModel(Request $request, $kit_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
@ -264,9 +258,8 @@ class PredefinedKitsController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function updateModel(Request $request, $kit_id, $model_id)
public function updateModel(Request $request, $kit_id, $model_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -283,9 +276,8 @@ class PredefinedKitsController extends Controller
* Remove the specified resource from storage.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function detachModel($kit_id, $model_id)
public function detachModel($kit_id, $model_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -299,9 +291,8 @@ class PredefinedKitsController extends Controller
* Display the specified resource.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function indexConsumables($kit_id)
public function indexConsumables($kit_id) : array
{
$this->authorize('view', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -314,9 +305,8 @@ class PredefinedKitsController extends Controller
* Store the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function storeConsumable(Request $request, $kit_id)
public function storeConsumable(Request $request, $kit_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
@ -342,9 +332,8 @@ class PredefinedKitsController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function updateConsumable(Request $request, $kit_id, $consumable_id)
public function updateConsumable(Request $request, $kit_id, $consumable_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -361,9 +350,8 @@ class PredefinedKitsController extends Controller
* Remove the specified resource from storage.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function detachConsumable($kit_id, $consumable_id)
public function detachConsumable($kit_id, $consumable_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -377,9 +365,8 @@ class PredefinedKitsController extends Controller
* Display the specified resource.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function indexAccessories($kit_id)
public function indexAccessories($kit_id) : array
{
$this->authorize('view', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -392,9 +379,8 @@ class PredefinedKitsController extends Controller
* Store the specified resource.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function storeAccessory(Request $request, $kit_id)
public function storeAccessory(Request $request, $kit_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
@ -420,9 +406,8 @@ class PredefinedKitsController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function updateAccessory(Request $request, $kit_id, $accessory_id)
public function updateAccessory(Request $request, $kit_id, $accessory_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);
@ -439,9 +424,8 @@ class PredefinedKitsController extends Controller
* Remove the specified resource from storage.
*
* @param int $kit_id
* @return \Illuminate\Http\Response
*/
public function detachAccessory($kit_id, $accessory_id)
public function detachAccessory($kit_id, $accessory_id) : JsonResponse
{
$this->authorize('update', PredefinedKit::class);
$kit = PredefinedKit::findOrFail($kit_id);

View file

@ -6,13 +6,13 @@ use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Models\CheckoutRequest;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Laravel\Passport\TokenRepository;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Illuminate\Support\Facades\Gate;
use App\Models\CustomField;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\JsonResponse;
class ProfileController extends Controller
{
@ -42,10 +42,8 @@ class ProfileController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.3.0]
*
* @return array
*/
public function requestedAssets()
public function requestedAssets() : array
{
$checkoutRequests = CheckoutRequest::where('user_id', '=', auth()->id())->get();
@ -95,10 +93,9 @@ class ProfileController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v6.0.5]
*
* @return \Illuminate\Http\Response
*/
public function createApiToken(Request $request) {
public function createApiToken(Request $request) : JsonResponse
{
if (!Gate::allows('self.api')) {
abort(403);
@ -125,10 +122,9 @@ class ProfileController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v6.0.5]
*
* @return \Illuminate\Http\Response
*/
public function deleteApiToken($tokenId) {
public function deleteApiToken($tokenId) : Response
{
if (!Gate::allows('self.api')) {
abort(403);
@ -154,10 +150,9 @@ class ProfileController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v6.0.5]
*
* @return \Illuminate\Http\Response
*/
public function showApiTokens(Request $request) {
public function showApiTokens() : JsonResponse
{
if (!Gate::allows('self.api')) {
abort(403);

View file

@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Http\Transformers\ActionlogsTransformer;
use App\Models\Actionlog;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
class ReportsController extends Controller
{
@ -14,9 +15,8 @@ class ReportsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Contracts\View\View
*/
public function index(Request $request)
public function index(Request $request) : JsonResponse | array
{
$this->authorize('reports.view');

View file

@ -9,26 +9,22 @@ use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Ldap;
use App\Models\Setting;
use Mail;
use App\Notifications\SlackTest;
use App\Notifications\MailTest;
use GuzzleHttp\Client;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use App\Http\Requests\SlackSettingsRequest;
use App\Http\Transformers\LoginAttemptsTransformer;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class SettingsController extends Controller
{
public function ldaptest()
public function ldaptest() : JsonResponse
{
$settings = Setting::getSettings();
@ -88,7 +84,7 @@ class SettingsController extends Controller
}
public function ldaptestlogin(Request $request)
public function ldaptestlogin(Request $request) : JsonResponse
{
if (Setting::getSettings()->ldap_enabled != '1') {
@ -148,9 +144,8 @@ class SettingsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @return \Illuminate\Http\JsonResponse
*/
public function ajaxTestEmail()
public function ajaxTestEmail() : JsonResponse
{
if (!config('app.lock_passwords')) {
try {
@ -170,9 +165,8 @@ class SettingsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v5.0.0]
* @return \Illuminate\Http\JsonResponse
*/
public function purgeBarcodes()
public function purgeBarcodes() : JsonResponse
{
$file_count = 0;
$files = Storage::disk('public')->files('barcodes');
@ -211,9 +205,8 @@ class SettingsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v5.0.0]
* @param \Illuminate\Http\Request $request
* @return array | JsonResponse
*/
public function showLoginAttempts(Request $request)
public function showLoginAttempts(Request $request) : array
{
$allowed_columns = ['id', 'username', 'remote_ip', 'user_agent', 'successful', 'created_at'];
@ -233,9 +226,9 @@ class SettingsController extends Controller
* Lists backup files
*
* @author [A. Gianotto]
* @return array | JsonResponse
*/
public function listBackups() {
public function listBackups() : array
{
$settings = Setting::getSettings();
$path = 'app/backups';
$backup_files = Storage::files($path);
@ -276,9 +269,9 @@ class SettingsController extends Controller
* exhausts memory on larger files.
*
* @author [A. Gianotto]
* @return \Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function downloadBackup($file) {
public function downloadBackup($file) : JsonResponse | BinaryFileResponse
{
$path = storage_path('app/backups');
@ -296,9 +289,9 @@ class SettingsController extends Controller
*
* @author [A. Gianotto]
* @since [v6.3.1]
* @return \Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function downloadLatestBackup() {
public function downloadLatestBackup() : JsonResponse | BinaryFileResponse
{
$fileData = collect();
foreach (Storage::files('app/backups') as $file) {

View file

@ -11,7 +11,7 @@ use App\Models\Asset;
use App\Models\Statuslabel;
use Illuminate\Http\Request;
use App\Http\Transformers\PieChartTransformer;
use Illuminate\Support\Arr;
use Illuminate\Http\JsonResponse;
class StatuslabelsController extends Controller
{
@ -20,9 +20,8 @@ class StatuslabelsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request) : array
{
$this->authorize('view', Statuslabel::class);
$allowed_columns = ['id', 'name', 'created_at', 'assets_count', 'color', 'notes', 'default_label'];
@ -72,9 +71,8 @@ class StatuslabelsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request) : JsonResponse
{
$this->authorize('create', Statuslabel::class);
$request->except('deployable', 'pending', 'archived');
@ -108,9 +106,8 @@ class StatuslabelsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', Statuslabel::class);
$statuslabel = Statuslabel::findOrFail($id);
@ -126,9 +123,8 @@ class StatuslabelsController extends Controller
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $id) : JsonResponse
{
$this->authorize('update', Statuslabel::class);
$statuslabel = Statuslabel::findOrFail($id);
@ -163,9 +159,8 @@ class StatuslabelsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Statuslabel::class);
$statuslabel = Statuslabel::findOrFail($id);
@ -188,9 +183,8 @@ class StatuslabelsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @return array
*/
public function getAssetCountByStatuslabel()
public function getAssetCountByStatuslabel() : array
{
$this->authorize('view', Statuslabel::class);
$statuslabels = Statuslabel::withCount('assets')->get();
@ -215,9 +209,8 @@ class StatuslabelsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v6.0.11]
* @return array
*/
public function getAssetCountByMetaStatus()
public function getAssetCountByMetaStatus() : array
{
$this->authorize('view', Statuslabel::class);
@ -245,9 +238,8 @@ class StatuslabelsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function assets(Request $request, $id)
public function assets(Request $request, $id) : array
{
$this->authorize('view', Statuslabel::class);
$this->authorize('index', Asset::class);
@ -281,9 +273,8 @@ class StatuslabelsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @return bool
*/
public function checkIfDeployable($id)
public function checkIfDeployable($id) : string
{
$statuslabel = Statuslabel::findOrFail($id);
if ($statuslabel->getStatuslabelType() == 'deployable') {
@ -300,7 +291,7 @@ class StatuslabelsController extends Controller
* @since [v6.1.1]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$this->authorize('view.selectlists');

View file

@ -10,6 +10,7 @@ use App\Models\Supplier;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\JsonResponse;
class SuppliersController extends Controller
{
@ -20,7 +21,7 @@ class SuppliersController extends Controller
* @since [v4.0]
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
public function index(Request $request): array
{
$this->authorize('view', Supplier::class);
$allowed_columns = ['
@ -114,9 +115,8 @@ class SuppliersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ImageUploadRequest $request)
public function store(ImageUploadRequest $request) : JsonResponse
{
$this->authorize('create', Supplier::class);
$supplier = new Supplier;
@ -136,9 +136,8 @@ class SuppliersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show($id) : array
{
$this->authorize('view', Supplier::class);
$supplier = Supplier::findOrFail($id);
@ -154,9 +153,8 @@ class SuppliersController extends Controller
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ImageUploadRequest $request, $id)
public function update(ImageUploadRequest $request, $id) : JsonResponse
{
$this->authorize('update', Supplier::class);
$supplier = Supplier::findOrFail($id);
@ -176,9 +174,8 @@ class SuppliersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($id) : JsonResponse
{
$this->authorize('delete', Supplier::class);
$supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances as asset_maintenances_count', 'assets as assets_count', 'licenses as licenses_count')->findOrFail($id);
@ -209,7 +206,7 @@ class SuppliersController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$this->authorize('view.selectlists');

View file

@ -24,6 +24,7 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Log;
use App\Http\Requests\DeleteUserRequest;
use Illuminate\Http\JsonResponse;
class UsersController extends Controller
{
@ -35,7 +36,7 @@ class UsersController extends Controller
*
* @return array
*/
public function index(Request $request)
public function index(Request $request) : array
{
$this->authorize('view', User::class);
@ -301,7 +302,7 @@ class UsersController extends Controller
* @since [v4.0.16]
* @see \App\Http\Transformers\SelectlistTransformer
*/
public function selectlist(Request $request)
public function selectlist(Request $request) : array
{
$users = User::select(
[
@ -357,9 +358,8 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @return array | \Illuminate\Http\JsonResponse
*/
public function store(SaveUserRequest $request)
public function store(SaveUserRequest $request) : JsonResponse
{
$this->authorize('create', User::class);
@ -404,9 +404,8 @@ class UsersController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $id
* @return array | \Illuminate\Http\JsonResponse
*/
public function show($id)
public function show($id) : JsonResponse | array
{
$this->authorize('view', User::class);
@ -427,9 +426,8 @@ class UsersController extends Controller
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\JsonResponse
*/
public function update(SaveUserRequest $request, $id)
public function update(SaveUserRequest $request, $id) : JsonResponse
{
$this->authorize('update', User::class);
@ -518,9 +516,8 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\JsonResponse
*/
public function destroy(DeleteUserRequest $request, $id)
public function destroy(DeleteUserRequest $request, $id) : JsonResponse
{
$this->authorize('delete', User::class);
@ -556,9 +553,8 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @param $userId
* @return array | \Illuminate\Http\JsonResponse
*/
public function assets(Request $request, $id)
public function assets(Request $request, $id) : JsonResponse | array
{
$this->authorize('view', User::class);
$this->authorize('view', Asset::class);
@ -601,9 +597,9 @@ class UsersController extends Controller
* @since [v6.0.13]
* @param Request $request
* @param $id
* @return string JSON
*/
public function emailAssetList(Request $request, $id)
public function emailAssetList(Request $request, $id) : JsonResponse
{
$this->authorize('update', User::class);
@ -629,9 +625,8 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @param $userId
* @return array | \Illuminate\Http\JsonResponse
*/
public function consumables(Request $request, $id)
public function consumables(Request $request, $id) : array
{
$this->authorize('view', User::class);
$this->authorize('view', Consumable::class);
@ -647,9 +642,8 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.6.14]
* @param $userId
* @return array
*/
public function accessories($id)
public function accessories($id) : array
{
$this->authorize('view', User::class);
$user = User::findOrFail($id);
@ -666,9 +660,8 @@ class UsersController extends Controller
* @author [N. Mathar] [<snipe@snipe.net>]
* @since [v5.0]
* @param $userId
* @return array | \Illuminate\Http\JsonResponse
*/
public function licenses($id)
public function licenses($id) : JsonResponse | array
{
$this->authorize('view', User::class);
$this->authorize('view', License::class);
@ -689,9 +682,8 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @param $userId
* @return string JSON
*/
public function postTwoFactorReset(Request $request)
public function postTwoFactorReset(Request $request) : JsonResponse
{
$this->authorize('update', User::class);
@ -729,9 +721,8 @@ class UsersController extends Controller
* @author [Juan Font] [<juanfontalonso@gmail.com>]
* @since [v4.4.2]
* @param \Illuminate\Http\Request $request
* @return array
*/
public function getCurrentUserInfo(Request $request)
public function getCurrentUserInfo(Request $request) : array
{
return (new UsersTransformer)->transformUser($request->user());
}
@ -742,9 +733,8 @@ class UsersController extends Controller
* @author [E. Taylor] [<dev@evantaylor.name>]
* @param int $userId
* @since [v6.0.0]
* @return \Illuminate\Http\JsonResponse
*/
public function restore($userId)
public function restore($userId) : JsonResponse
{
$this->authorize('delete', User::class);