• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

conedevelopment / bazar / 20694116184

04 Jan 2026 02:08PM UTC coverage: 68.615% (+4.5%) from 64.117%
20694116184

push

github

iamgergo
version

1679 of 2447 relevant lines covered (68.61%)

25.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.05
/src/Resources/CouponResource.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Resources;
6

7
use Cone\Bazar\Enums\DiscountType;
8
use Cone\Bazar\Models\Coupon;
9
use Cone\Root\Fields\Boolean;
10
use Cone\Root\Fields\Date;
11
use Cone\Root\Fields\Fieldset;
12
use Cone\Root\Fields\ID;
13
use Cone\Root\Fields\Number;
14
use Cone\Root\Fields\Select;
15
use Cone\Root\Fields\Text;
16
use Cone\Root\Resources\Resource;
17
use Illuminate\Database\Eloquent\Model;
18
use Illuminate\Http\Request;
19
use Illuminate\Validation\Rule;
20

21
class CouponResource extends Resource
22
{
23
    /**
24
     * The model class.
25
     */
26
    protected string $model = Coupon::class;
27

28
    /**
29
     * The group for the resource.
30
     */
31
    protected string $group = 'Shop';
32

33
    /**
34
     * The relations to eager load on every query.
35
     */
36
    protected array $withCount = [
37
        'applications',
38
    ];
39

40
    /**
41
     * Get the model for the resource.
42
     */
43
    public function getModel(): string
101✔
44
    {
45
        return $this->model::getProxiedClass();
101✔
46
    }
47

48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function modelTitle(Model $model): string
×
52
    {
53
        return $model->code;
×
54
    }
55

56
    /**
57
     * Define the fields.
58
     */
59
    public function fields(Request $request): array
101✔
60
    {
61
        return [
101✔
62
            ID::make(),
101✔
63

64
            Text::make(__('Code'), 'code')
101✔
65
                ->rules(['required', 'string', 'max:256'])
101✔
66
                ->searchable()
101✔
67
                ->sortable()
101✔
68
                ->required(),
101✔
69

70
            Select::make(__('Type'), 'type')
101✔
71
                ->options(DiscountType::toArray())
101✔
72
                ->required()
101✔
73
                ->rules(['required', Rule::in(array_column(DiscountType::cases(), 'value'))]),
101✔
74

75
            Number::make(__('Value'), 'value')
101✔
76
                ->required()
101✔
77
                ->rules(['required', 'numeric', 'min:0'])
101✔
78
                ->step(0.1)
101✔
79
                ->min(0)
101✔
80
                ->format(static function (Request $request, Model $model): string {
101✔
81
                    return (string) match ($model->type) {
×
82
                        DiscountType::PERCENT => $model->value.'%',
×
83
                        default => $model->value,
×
84
                    };
×
85
                }),
101✔
86

87
            Boolean::make(__('Active'), 'active')
101✔
88
                ->sortable(),
101✔
89

90
            Date::make(__('Expires At'), 'expires_at')
101✔
91
                ->withTime()
101✔
92
                ->sortable(),
101✔
93

94
            Boolean::make(__('Stackable'), 'stackable')
101✔
95
                ->sortable(),
101✔
96

97
            Fieldset::make(__('Rules'), 'rules')
101✔
98
                ->withFields(static function (): array {
101✔
99
                    return [
101✔
100
                        Number::make(__('Limit'), 'rules->limit')
101✔
101
                            ->min(0)
101✔
102
                            ->rules(['nullable', 'numeric', 'min:0']),
101✔
103
                    ];
101✔
104
                }),
101✔
105
        ];
101✔
106
    }
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc