Store::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
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