Completed
Push — master ( 2f247e...1e7a22 )
by ruthger
01:44
created

Regenerate::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RuthgerIdema\UrlRewrite\Nova\Actions;
6
7
use Illuminate\Bus\Queueable;
8
use Laravel\Nova\Actions\Action;
9
use Illuminate\Support\Collection;
10
use Laravel\Nova\Fields\ActionFields;
11
use Illuminate\Queue\SerializesModels;
12
use Illuminate\Queue\InteractsWithQueue;
13
use RuthgerIdema\UrlRewrite\Facades\UrlRewrite;
14
15
class Regenerate extends Action
16
{
17
    use InteractsWithQueue, Queueable, SerializesModels;
18
19
    public function handle(ActionFields $fields, Collection $models)
20
    {
21
        $i = 0;
22
        foreach ($models as $model) {
23
            try {
24
                UrlRewrite::regenerateRoute($model);
25
                $i++;
26
            } catch (\Exception $exception) {
27
                return Action::danger("$i done, $model->id failed: $exception->getMessage()");
0 ignored issues
show
Bug introduced by
The property getMessage does not seem to exist. Did you mean message?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
28
            }
29
        }
30
31
        return Action::message($i.' '.trans('urlrewrites::translations.regenerated'));
32
    }
33
}
34