Test Setup Failed
Push — main ( 37e03b...339976 )
by Mohamed
11:31
created

Store::getValidationAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Actions\Testimonial;
4
5
use App\Mail\TestimonialSubmitted;
6
use App\Models\Testimonial;
7
use Illuminate\Support\Facades\Mail;
8
use Lorisleiva\Actions\Concerns\AsAction;
9
use Lorisleiva\Actions\Concerns\WithAttributes;
10
11
class Store
12
{
13
    use AsAction, WithAttributes;
14
15
    /**
16
     * Get the validation rules that apply to the action.
17
     *
18
     * @return array
19
     */
20
    public function rules(): array
21
    {
22
        return [
23
            'avatar'   => 'sometimes|nullable|image|mimes:jpeg,jpg,png|max:2048',
24
            'name'     => 'required|string|min:3',
25
            'email'    => 'required|string|email',
26
            'position' => 'required|string|min:3',
27
            'body'     => 'required|string|min:20',
28
            'stars'    => 'required|integer|max:5',
29
        ];
30
    }
31
32
    /**
33
     * Define validation attributes.
34
     *
35
     * @return array
36
     */
37
    public function getValidationAttributes()
38
    {
39
        return [
40
            'body' => 'testimonial',
41
        ];
42
    }
43
44
    /**
45
     * Execute the action and return a result.
46
     *
47
     * @return mixed
48
     */
49
    public function handle(array $attributes): Testimonial
50
    {
51
        $this->fill($attributes);
52
53
        $testimonial = Testimonial::create($this->validateAttributes());
54
55
        Mail::to($testimonial->email)->send(new TestimonialSubmitted($testimonial->toArray()));
56
57
        return $testimonial;
58
    }
59
}
60