mirror of
https://github.com/snipe/snipe-it.git
synced 2026-03-01 05:17:45 +00:00
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Actions\Suppliers\DestroySupplierAction;
|
|
use App\Exceptions\ModelStillHasAssetMaintenances;
|
|
use App\Exceptions\ModelStillHasAssets;
|
|
use App\Exceptions\ModelStillHasLicenses;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BulkSuppliersController extends Controller
|
|
{
|
|
public function destroy($ids)
|
|
{
|
|
$errors = [];
|
|
foreach ($ids as $id) {
|
|
try {
|
|
DestroySupplierAction::run(supplier: $id);
|
|
} catch (ModelStillHasAssets $e) {
|
|
$errors[] = `{$id} still has assets`;
|
|
} catch (ModelStillHasAssetMaintenances $e) {
|
|
$errors[] = `{$id} still has asset maintenances`;
|
|
} catch (ModelStillHasLicenses $e) {
|
|
$errors[] = `{$id} still has licenses`;
|
|
} catch (\Exception $e) {
|
|
report($e);
|
|
$errors[] = 'Something went wrong';
|
|
}
|
|
}
|
|
if (count($errors) > 0) {
|
|
return redirect()->route('suppliers.index')->with('error', implode(', ', $errors));
|
|
} else {
|
|
return redirect()->route('suppliers.index')->with('success', trans('admin/suppliers/message.delete.success'));
|
|
}
|
|
}
|
|
}
|