Store   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 8 1
A handle() 0 9 1
1
<?php
2
3
namespace App\Actions\ContactMessage;
4
5
use App\Mail\ContactMessageSent;
6
use App\Models\ContactMessage;
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
            'name'     => 'required|string|min:3',
24
            'email'    => 'required|string|email',
25
            'position' => 'nullable|string|min:3',
26
            'subject'  => 'required|string|min:3',
27
            'body'     => 'required|string|min:10',
28
        ];
29
    }
30
31
    /**
32
     * Execute the action and return a result.
33
     *
34
     * @return mixed
35
     */
36
    public function handle(array $attributes): ContactMessage
37
    {
38
        $this->fill($attributes);
39
40
        $message = ContactMessage::create($this->validateAttributes());
41
42
        Mail::to($message->email)->send(new ContactMessageSent($message->toArray()));
43
44
        return $message;
45
    }
46
}
47