-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathRejectSupportApproval.php
More file actions
45 lines (36 loc) · 1.13 KB
/
RejectSupportApproval.php
File metadata and controls
45 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace App\Nova\Actions;
use App\Models\Support\SupportApproval;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
class RejectSupportApproval extends Action
{
use Queueable;
public $name = 'Reject';
public function fields(NovaRequest $request): array
{
return [
Text::make('Reason', 'reason')
->rules('required', 'max:500'),
];
}
public function handle(ActionFields $fields, Collection $models)
{
/** @var SupportApproval $approval */
foreach ($models as $approval) {
if ($approval->status !== 'pending') {
continue;
}
$approval->status = 'rejected';
$approval->approved_by = optional(auth()->user())->email ?? 'nova';
$approval->approved_at = now();
$approval->rejected_reason = (string) $fields->reason;
$approval->save();
}
return Action::message('Rejected.');
}
}