ContactController::validateContact()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Robertgarrigos\Contact\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Routing\Controller;
7
use Illuminate\Support\Facades\Mail;
8
use Illuminate\Support\Facades\Redirect;
9
use Robertgarrigos\Contact\Models\Contact;
10
use Robertgarrigos\Contact\Mail\MessageSent;
11
12
class ContactController extends Controller
13
{
14
    public function index()
15
    {
16
        return view('contact::contact');
17
    }
18
19
    public function store(Request $request)
20
    {
21
        $attributes = $this->validateContact();
22
23
        $name = $attributes['name'];
24
        $email = $attributes['email'];
25
        $message = $attributes['message'];
26
        //SendMail
27
28
        try {
29
            Mail::to(config('contact.email'))
30
                ->send(new MessageSent($name, $email, $message));
31
32
            // Save the message details to database
33
            Contact::create($attributes);
34
35
            return redirect(route('contact'))->with(['message' => __('contact.message_sent')]);
36
        } catch (\Swift_TransportException $e) {
0 ignored issues
show
Bug introduced by
The class Swift_TransportException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
37
            // email address from contacter is not a real one, even it is well formed
38
            session()->flashInput($request->input());
39
40
            return Redirect::back()->withErrors(['email' => __('contact.email_not_valid')]);
41
        }
42
    }
43
44
    public function validateContact()
45
    {
46
        return request()->validate([
47
            'name' => 'required|min:3',
48
            'email' => 'required|email',
49
            'message' => 'required|min:3',
50
            'captcha' => 'required|captcha',
51
        ]);
52
    }
53
}
54