some tests, a component i probably won't use, beginning of front end
This commit is contained in:
@@ -10,18 +10,37 @@ use App\Exceptions\ModelStillHasAssets;
|
||||
use App\Exceptions\ModelStillHasComponents;
|
||||
use App\Exceptions\ModelStillHasConsumables;
|
||||
use App\Exceptions\ModelStillHasLicenses;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BulkCategoriesController extends Controller
|
||||
{
|
||||
public function destroy($ids)
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
// Authorize the user to delete categories
|
||||
$this->authorize('delete', Category::class);
|
||||
|
||||
$errors = [];
|
||||
foreach ($ids as $id) {
|
||||
foreach ($request->ids as $id) {
|
||||
$category = Category::find($id);
|
||||
if (is_null($category)) {
|
||||
$errors[] = 'Category not found';
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
DestroyCategoryAction::run(category: $id);
|
||||
} catch (ModelStillHasAccessories|ModelStillHasAssetModels|ModelStillHasAssets|ModelStillHasComponents|ModelStillHasConsumables|ModelStillHasLicenses $e) {
|
||||
$errors[] = `{$id} still has {$id->thing}`;
|
||||
DestroyCategoryAction::run(category: $category);
|
||||
} catch (ModelStillHasAccessories $e) {
|
||||
$errors[] = "{$category->name} still has associated items";
|
||||
} catch (ModelStillHasAssetModels) {
|
||||
$errors[] = "{$category->name} still has asset models";
|
||||
} catch (ModelStillHasAssets) {
|
||||
$errors[] = "{$category->name} still has assets";
|
||||
} catch (ModelStillHasComponents) {
|
||||
$errors[] = "{$category->name} still has components";
|
||||
} catch (ModelStillHasConsumables) {
|
||||
$errors[] = "{$category->name} still has consumables";
|
||||
} catch (ModelStillHasLicenses) {
|
||||
$errors[] = "{$category->name} still has licenses";
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
$errors[] = 'Something went wrong';
|
||||
@@ -30,7 +49,7 @@ class BulkCategoriesController extends Controller
|
||||
if (count($errors) > 0) {
|
||||
return redirect()->route('categories.index')->with('error', implode(', ', $errors));
|
||||
} else {
|
||||
return redirect()->route('categories.index')->with('success', trans('admin/suppliers/message.delete.success'));
|
||||
return redirect()->route('categories.index')->with('success', trans('admin/categories/message.delete.success'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user