rename all exceptions
This commit is contained in:
@@ -2,26 +2,24 @@
|
||||
|
||||
namespace App\Actions\Categories;
|
||||
|
||||
use App\Exceptions\ModelIsNotDeletable;
|
||||
use App\Exceptions\ModelStillHasAccessories;
|
||||
use App\Exceptions\ModelStillHasAssetModels;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Helpers\Helper;
|
||||
use App\Exceptions\ItemStillHasAccessories;
|
||||
use App\Exceptions\ItemStillHasAssetModels;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasComponents;
|
||||
use App\Exceptions\ItemStillHasConsumables;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class DestroyCategoryAction
|
||||
{
|
||||
/**
|
||||
* @throws ModelStillHasAssets
|
||||
* @throws ModelStillHasAssetModels
|
||||
* @throws ModelStillHasComponents
|
||||
* @throws ModelStillHasAccessories
|
||||
* @throws ModelStillHasLicenses
|
||||
* @throws ModelStillHasConsumables
|
||||
* @throws ItemStillHasAssets
|
||||
* @throws ItemStillHasAssetModels
|
||||
* @throws ItemStillHasComponents
|
||||
* @throws ItemStillHasAccessories
|
||||
* @throws ItemStillHasLicenses
|
||||
* @throws ItemStillHasConsumables
|
||||
*/
|
||||
static function run(Category $category): bool
|
||||
{
|
||||
@@ -35,22 +33,22 @@ class DestroyCategoryAction
|
||||
]);
|
||||
|
||||
if ($category->assets_count > 0) {
|
||||
throw new ModelStillHasAssets($category);
|
||||
throw new ItemStillHasAssets($category);
|
||||
}
|
||||
if ($category->accessories_count > 0) {
|
||||
throw new ModelStillHasAccessories($category);
|
||||
throw new ItemStillHasAccessories($category);
|
||||
}
|
||||
if ($category->consumables_count > 0) {
|
||||
throw new ModelStillHasConsumables($category);
|
||||
throw new ItemStillHasConsumables($category);
|
||||
}
|
||||
if ($category->components_count > 0) {
|
||||
throw new ModelStillHasComponents($category);
|
||||
throw new ItemStillHasComponents($category);
|
||||
}
|
||||
if ($category->licenses_count > 0) {
|
||||
throw new ModelStillHasLicenses($category);
|
||||
throw new ItemStillHasLicenses($category);
|
||||
}
|
||||
if ($category->models_count > 0) {
|
||||
throw new ModelStillHasAssetModels($category);
|
||||
throw new ItemStillHasAssetModels($category);
|
||||
}
|
||||
|
||||
Storage::disk('public')->delete('categories'.'/'.$category->image);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Actions\Manufacturers;
|
||||
|
||||
use App\Exceptions\ModelStillHasAccessories;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasAccessories;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasComponents;
|
||||
use App\Exceptions\ItemStillHasConsumables;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Models\Manufacturer;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -14,11 +14,11 @@ use Illuminate\Support\Facades\Storage;
|
||||
class DeleteManufacturerAction
|
||||
{
|
||||
/**
|
||||
* @throws ModelStillHasAssets
|
||||
* @throws ModelStillHasComponents
|
||||
* @throws ModelStillHasAccessories
|
||||
* @throws ModelStillHasLicenses
|
||||
* @throws ModelStillHasConsumables
|
||||
* @throws ItemStillHasAssets
|
||||
* @throws ItemStillHasComponents
|
||||
* @throws ItemStillHasAccessories
|
||||
* @throws ItemStillHasLicenses
|
||||
* @throws ItemStillHasConsumables
|
||||
*/
|
||||
static function run(Manufacturer $manufacturer): bool
|
||||
{
|
||||
@@ -31,19 +31,19 @@ class DeleteManufacturerAction
|
||||
]);
|
||||
|
||||
if ($manufacturer->assets_count > 0) {
|
||||
throw new ModelStillHasAssets($manufacturer);
|
||||
throw new ItemStillHasAssets($manufacturer);
|
||||
}
|
||||
if ($manufacturer->accessories_count > 0) {
|
||||
throw new ModelStillHasAccessories($manufacturer);
|
||||
throw new ItemStillHasAccessories($manufacturer);
|
||||
}
|
||||
if ($manufacturer->consumables_count > 0) {
|
||||
throw new ModelStillHasConsumables($manufacturer);
|
||||
throw new ItemStillHasConsumables($manufacturer);
|
||||
}
|
||||
if ($manufacturer->components_count > 0) {
|
||||
throw new ModelStillHasComponents($manufacturer);
|
||||
throw new ItemStillHasComponents($manufacturer);
|
||||
}
|
||||
if ($manufacturer->licenses_count > 0) {
|
||||
throw new ModelStillHasLicenses($manufacturer);
|
||||
throw new ItemStillHasLicenses($manufacturer);
|
||||
}
|
||||
|
||||
if ($manufacturer->image) {
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
namespace App\Actions\Suppliers;
|
||||
|
||||
use App\Models\Supplier;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasMaintenances;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasMaintenances;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class DestroySupplierAction
|
||||
{
|
||||
/**
|
||||
* @throws ModelStillHasLicenses
|
||||
* @throws ModelStillHasAssets
|
||||
* @throws ModelStillHasMaintenances
|
||||
* @throws ItemStillHasLicenses
|
||||
* @throws ItemStillHasAssets
|
||||
* @throws ItemStillHasMaintenances
|
||||
*/
|
||||
static function run(Supplier $supplier): bool
|
||||
{
|
||||
@@ -24,15 +24,15 @@ class DestroySupplierAction
|
||||
'licenses as licenses_count'
|
||||
]);
|
||||
if ($supplier->assets_count > 0) {
|
||||
throw new ModelStillHasAssets($supplier);
|
||||
throw new ItemStillHasAssets($supplier);
|
||||
}
|
||||
|
||||
if ($supplier->maintenances_count > 0) {
|
||||
throw new ModelStillHasMaintenances($supplier);
|
||||
throw new ItemStillHasMaintenances($supplier);
|
||||
}
|
||||
|
||||
if ($supplier->licenses_count > 0) {
|
||||
throw new ModelStillHasLicenses($supplier);
|
||||
throw new ItemStillHasLicenses($supplier);
|
||||
}
|
||||
|
||||
if ($supplier->image) {
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasComponents extends ModelStillHasChildren
|
||||
class ItemStillHasAccessories extends ItemStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasAssetModels extends ModelStillHasChildren
|
||||
class ItemStillHasAssetModels extends ItemStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
9
app/Exceptions/ItemStillHasAssets.php
Normal file
9
app/Exceptions/ItemStillHasAssets.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ItemStillHasAssets extends ItemStillHasChildren
|
||||
{
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasChildren extends Exception
|
||||
class ItemStillHasChildren extends Exception
|
||||
{
|
||||
//public function __construct($message, $code = 0, Exception $previous = null, $parent, $children)
|
||||
//{
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasLicenses extends ModelStillHasChildren
|
||||
class ItemStillHasComponents extends ItemStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasConsumables extends ModelStillHasChildren
|
||||
class ItemStillHasConsumables extends ItemStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
10
app/Exceptions/ItemStillHasLicenses.php
Normal file
10
app/Exceptions/ItemStillHasLicenses.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ItemStillHasLicenses extends ItemStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
10
app/Exceptions/ItemStillHasMaintenances.php
Normal file
10
app/Exceptions/ItemStillHasMaintenances.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ItemStillHasMaintenances extends ItemStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasAccessories extends ModelStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasAssets extends ModelStillHasChildren
|
||||
{
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ModelStillHasMaintenances extends ModelStillHasChildren
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Actions\Categories\DestroyCategoryAction;
|
||||
use App\Exceptions\ModelStillHasChildren;
|
||||
use App\Exceptions\ItemStillHasChildren;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Transformers\CategoriesTransformer;
|
||||
@@ -216,7 +216,7 @@ class CategoriesController extends Controller
|
||||
$this->authorize('delete', Category::class);
|
||||
try {
|
||||
DestroyCategoryAction::run(category: $category);
|
||||
} catch (ModelStillHasChildren $e) {
|
||||
} catch (ItemStillHasChildren $e) {
|
||||
return response()->json(
|
||||
Helper::formatStandardApiResponse('error', null, trans('admin/categories/message.assoc_items', ['asset_type' => $category->category_type]))
|
||||
);
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Actions\Manufacturers\DeleteManufacturerAction;
|
||||
use App\Exceptions\ModelStillHasAccessories;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasChildren;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasAccessories;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasChildren;
|
||||
use App\Exceptions\ItemStillHasComponents;
|
||||
use App\Exceptions\ItemStillHasConsumables;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Transformers\ManufacturersTransformer;
|
||||
@@ -196,7 +196,7 @@ class ManufacturersController extends Controller
|
||||
$this->authorize('delete', $manufacturer);
|
||||
try {
|
||||
DeleteManufacturerAction::run($manufacturer);
|
||||
} catch (ModelStillHasChildren $e) {
|
||||
} catch (ItemStillHasChildren $e) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/manufacturers/message.assoc_users')));
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong')));
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Actions\Suppliers\DestroySupplierAction;
|
||||
use App\Exceptions\ModelStillHasMaintenances;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasMaintenances;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Transformers\SelectlistTransformer;
|
||||
@@ -200,11 +200,11 @@ class SuppliersController extends Controller
|
||||
$this->authorize('delete', $supplier);
|
||||
try {
|
||||
DestroySupplierAction::run(supplier: $supplier);
|
||||
} catch (ModelStillHasAssets $e) {
|
||||
} catch (ItemStillHasAssets $e) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_assets', ['asset_count' => (int) $supplier->assets_count])));
|
||||
} catch (ModelStillHasMaintenances $e) {
|
||||
} catch (ItemStillHasMaintenances $e) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_maintenances', ['asset_maintenances_count' => $supplier->asset_maintenances_count])));
|
||||
} catch (ModelStillHasLicenses $e) {
|
||||
} catch (ItemStillHasLicenses $e) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_licenses', ['licenses_count' => (int) $supplier->licenses_count])));
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong')));
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Categories\DestroyCategoryAction;
|
||||
use App\Exceptions\ModelStillHasAccessories;
|
||||
use App\Exceptions\ModelStillHasAssetModels;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasAccessories;
|
||||
use App\Exceptions\ItemStillHasAssetModels;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasComponents;
|
||||
use App\Exceptions\ItemStillHasConsumables;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -27,17 +27,17 @@ class BulkCategoriesController extends Controller
|
||||
}
|
||||
try {
|
||||
DestroyCategoryAction::run(category: $category);
|
||||
} catch (ModelStillHasAccessories $e) {
|
||||
} catch (ItemStillHasAccessories $e) {
|
||||
$errors[] = trans('admin/categories/message.delete.bulk_assoc_accessories', ['category_name' => $category->name]);
|
||||
} catch (ModelStillHasAssetModels) {
|
||||
} catch (ItemStillHasAssetModels) {
|
||||
$errors[] = trans('admin/categories/message.delete.bulk_assoc_models', ['category_name' => $category->name]);
|
||||
} catch (ModelStillHasAssets) {
|
||||
} catch (ItemStillHasAssets) {
|
||||
$errors[] = trans('admin/categories/message.delete.bulk_assoc_assets', ['category_name' => $category->name]);
|
||||
} catch (ModelStillHasComponents) {
|
||||
} catch (ItemStillHasComponents) {
|
||||
$errors[] = trans('admin/categories/message.delete.bulk_assoc_components', ['category_name' => $category->name]);
|
||||
} catch (ModelStillHasConsumables) {
|
||||
} catch (ItemStillHasConsumables) {
|
||||
$errors[] = trans('admin/categories/message.delete.bulk_assoc_consumables', ['category_name' => $category->name]);
|
||||
} catch (ModelStillHasLicenses) {
|
||||
} catch (ItemStillHasLicenses) {
|
||||
$errors[] = trans('admin/categories/message.delete.bulk_assoc_licenses', ['category_name' => $category->name]);
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Manufacturers\DeleteManufacturerAction;
|
||||
use App\Exceptions\ModelStillHasAccessories;
|
||||
use App\Exceptions\ModelStillHasAssetModels;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasChildren;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasAccessories;
|
||||
use App\Exceptions\ItemStillHasAssetModels;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasChildren;
|
||||
use App\Exceptions\ItemStillHasComponents;
|
||||
use App\Exceptions\ItemStillHasConsumables;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Models\Manufacturer;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -28,15 +28,15 @@ class BulkManufacturersController extends Controller
|
||||
}
|
||||
try {
|
||||
DeleteManufacturerAction::run(manufacturer: $manufacturer);
|
||||
} catch (ModelStillHasAssets $e) {
|
||||
} catch (ItemStillHasAssets $e) {
|
||||
$errors[] = trans('admin/manufacturers/message.delete.bulk_assoc_assets', ['manufacturer_name' => $manufacturer->name]);
|
||||
} catch (ModelStillHasAccessories $e) {
|
||||
} catch (ItemStillHasAccessories $e) {
|
||||
$errors[] = trans('admin/manufacturers/message.delete.bulk_assoc_accessories', ['manufacturer_name' => $manufacturer->name]);
|
||||
} catch (ModelStillHasConsumables $e) {
|
||||
} catch (ItemStillHasConsumables $e) {
|
||||
$errors[] = trans('admin/manufacturers/message.delete.bulk_assoc_consumables', ['manufacturer_name' => $manufacturer->name]);
|
||||
} catch (ModelStillHasComponents $e) {
|
||||
} catch (ItemStillHasComponents $e) {
|
||||
$errors[] = trans('admin/manufacturers/message.delete.bulk_assoc_components', ['manufacturer_name' => $manufacturer->name]);;
|
||||
} catch (ModelStillHasLicenses $e) {
|
||||
} catch (ItemStillHasLicenses $e) {
|
||||
$errors[] = trans('admin/manufacturers/message.delete.bulk_assoc_licenses', ['manufacturer_name' => $manufacturer->name]);;
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Suppliers\DestroySupplierAction;
|
||||
use App\Exceptions\ModelStillHasMaintenances;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasMaintenances;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -24,11 +24,11 @@ class BulkSuppliersController extends Controller
|
||||
}
|
||||
try {
|
||||
DestroySupplierAction::run(supplier: $supplier);
|
||||
} catch (ModelStillHasAssets $e) {
|
||||
} catch (ItemStillHasAssets $e) {
|
||||
$errors[] = trans('admin/suppliers/message.delete.bulk_assoc_assets', ['supplier_name' => $supplier->name]);
|
||||
} catch (ModelStillHasMaintenances $e) {
|
||||
} catch (ItemStillHasMaintenances $e) {
|
||||
$errors[] = trans('admin/suppliers/message.delete.bulk_assoc_maintenances', ['supplier_name' => $supplier->name]);;
|
||||
} catch (ModelStillHasLicenses $e) {
|
||||
} catch (ItemStillHasLicenses $e) {
|
||||
$errors[] = trans('admin/suppliers/message.delete.bulk_assoc_licenses', ['supplier_name' => $supplier->name]);
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Categories\DestroyCategoryAction;
|
||||
use App\Exceptions\ModelStillHasAccessories;
|
||||
use App\Exceptions\ModelStillHasAssetModels;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasChildren;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasAccessories;
|
||||
use App\Exceptions\ItemStillHasAssetModels;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasChildren;
|
||||
use App\Exceptions\ItemStillHasComponents;
|
||||
use App\Exceptions\ItemStillHasConsumables;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use App\Models\Category;
|
||||
@@ -156,7 +156,7 @@ class CategoriesController extends Controller
|
||||
$this->authorize('delete', Category::class);
|
||||
try {
|
||||
DestroyCategoryAction::run($category);
|
||||
} catch (ModelStillHasChildren $e) {
|
||||
} catch (ItemStillHasChildren $e) {
|
||||
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.assoc_items', ['asset_type' => $category->category_type]));
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Manufacturers\DeleteManufacturerAction;
|
||||
use App\Exceptions\ModelStillHasAccessories;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasChildren;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasAccessories;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasChildren;
|
||||
use App\Exceptions\ItemStillHasComponents;
|
||||
use App\Exceptions\ItemStillHasConsumables;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use App\Models\Actionlog;
|
||||
@@ -170,7 +170,7 @@ class ManufacturersController extends Controller
|
||||
$this->authorize('delete', $manufacturer);
|
||||
try {
|
||||
DeleteManufacturerAction::run($manufacturer);
|
||||
} catch (ModelStillHasChildren $e) {
|
||||
} catch (ItemStillHasChildren $e) {
|
||||
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.assoc_users'));
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->route('manufacturers.index')->with('error', trans('general.something_went_wrong'));
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Suppliers\DestroySupplierAction;
|
||||
use App\Exceptions\ModelStillHasMaintenances;
|
||||
use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Exceptions\ItemStillHasMaintenances;
|
||||
use App\Exceptions\ItemStillHasAssets;
|
||||
use App\Exceptions\ItemStillHasLicenses;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use \Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* This controller handles all actions related to Suppliers for
|
||||
@@ -124,18 +125,23 @@ class SuppliersController extends Controller
|
||||
*/
|
||||
public function destroy(Supplier $supplier): RedirectResponse
|
||||
{
|
||||
$errors = new MessageBag();
|
||||
$this->authorize('delete', Supplier::class);
|
||||
try {
|
||||
DestroySupplierAction::run(supplier: $supplier);
|
||||
} catch (ModelStillHasAssets $e) {
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.assoc_assets', ['asset_count' => (int) $supplier->assets_count]));
|
||||
} catch (ModelStillHasMaintenances $e) {
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.assoc_maintenances', ['asset_maintenances_count' => $supplier->asset_maintenances_count]));
|
||||
} catch (ModelStillHasLicenses $e) {
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.assoc_licenses', ['licenses_count' => (int) $supplier->licenses_count]));
|
||||
} catch (ItemStillHasAssets $e) {
|
||||
$errors->add('error', trans('admin/suppliers/message.delete.assoc_assets', ['asset_count' => (int) $supplier->assets_count]));
|
||||
} catch (ItemStillHasMaintenances $e) {
|
||||
$errors->add('error', trans('admin/suppliers/message.delete.assoc_maintenances', ['asset_maintenances_count' => $supplier->asset_maintenances_count]));
|
||||
} catch (ItemStillHasLicenses $e) {
|
||||
$errors->add('error', trans('admin/suppliers/message.delete.assoc_licenses', ['licenses_count' => (int) $supplier->licenses_count]));
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.error'));
|
||||
$errors->add('error', trans('general.something_went_wrong'));
|
||||
}
|
||||
|
||||
if ($errors->count() > 0) {
|
||||
return redirect()->route('suppliers.index')->with('multi_errors', $errors);
|
||||
}
|
||||
|
||||
return redirect()->route('suppliers.index')->with('success', trans('admin/suppliers/message.delete.success'));
|
||||
|
||||
Reference in New Issue
Block a user