61 lines
1.7 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\BulkActions\Common;
use App\Abstracts\BulkAction;
use App\Exports\Common\Items as Export;
2019-12-23 12:46:00 +03:00
use App\Jobs\Common\DeleteItem;
2019-11-16 10:21:14 +03:00
use App\Models\Common\Item;
class Items extends BulkAction
{
public $model = Item::class;
public $actions = [
'enable' => [
'name' => 'general.enable',
'message' => 'bulk_actions.message.enable',
'path' => ['group' => 'common', 'type' => 'items'],
'type' => '*',
2019-12-23 12:46:00 +03:00
'permission' => 'update-common-items',
2019-11-16 10:21:14 +03:00
],
'disable' => [
'name' => 'general.disable',
'message' => 'bulk_actions.message.disable',
'path' => ['group' => 'common', 'type' => 'items'],
'type' => '*',
2019-12-23 12:46:00 +03:00
'permission' => 'update-common-items',
2019-11-16 10:21:14 +03:00
],
2019-12-23 12:46:00 +03:00
'delete' => [
'name' => 'general.delete',
'message' => 'bulk_actions.message.delete',
'permission' => 'delete-common-items',
2019-11-16 10:21:14 +03:00
],
'export' => [
'name' => 'general.export',
2019-12-23 12:46:00 +03:00
'message' => 'bulk_actions.message.export',
'type' => 'download',
2019-12-27 15:42:22 +03:00
],
2019-11-16 10:21:14 +03:00
];
public function destroy($request)
{
2019-12-23 12:46:00 +03:00
$items = $this->getSelectedRecords($request);
2019-11-16 10:21:14 +03:00
foreach ($items as $item) {
2019-12-23 12:46:00 +03:00
try {
$this->dispatch(new DeleteItem($item));
} catch (\Exception $e) {
flash($e->getMessage())->error()->important();
2019-11-16 10:21:14 +03:00
}
}
}
public function export($request)
{
2019-12-23 12:46:00 +03:00
$selected = $this->getSelectedInput($request);
2019-11-16 10:21:14 +03:00
return \Excel::download(new Export($selected), trans_choice('general.items', 2) . '.xlsx');
}
}