Skip to content

Commit

Permalink
Bulk actions message improved
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesSacid-Buker committed Feb 22, 2023
1 parent 7bc818c commit 8280229
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/Http/Controllers/Common/BulkActions.php
Expand Up @@ -61,19 +61,28 @@ public function action($group, $type, Request $request)

$result = $bulk_actions->{$handle}($request);

$message = trans($bulk_actions->messages['general'], ['type' => $handle, 'count' => count($request->get('selected'))]);
$count = count($request->get('selected'));
$not_passed = 0;

if (array_key_exists($handle, $bulk_actions->messages)) {
flash()->messages->each(function ($message) use (&$not_passed) {
if (in_array($message->level, ['danger', 'warning'])) {
$not_passed++;
}
});

$message = trans($bulk_actions->messages['general'], ['type' => $handle, 'count' => $count - $not_passed]);

if (array_key_exists($handle, $bulk_actions->messages) && $not_passed === 0) {
$message = trans($bulk_actions->messages[$handle], ['type' => $page]);
}

if (! empty($result) && ($result instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse)) {
flash($message)->success();
$level = $not_passed > 0 ? 'info' : 'success';

flash($message)->{$level}();

if (! empty($result) && ($result instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse)) {
return $result;
} elseif (! empty($result) && ($result instanceof RedirectResponse)) {
flash($message)->success();

return response()->json([
'success' => true,
'redirect' => $result->getTargetUrl(),
Expand All @@ -82,8 +91,6 @@ public function action($group, $type, Request $request)
'message' => ''
]);
} else {
flash($message)->success();

return response()->json([
'success' => true,
'redirect' => true,
Expand Down

0 comments on commit 8280229

Please sign in to comment.