gdiasdasilva /
benfica-live
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Controllers; |
||
| 4 | |||
| 5 | use App\ContactMessage; |
||
| 6 | use Illuminate\Http\Request; |
||
| 7 | use App\Mail\ContactSubmitted; |
||
| 8 | use Illuminate\Support\Facades\Log; |
||
| 9 | use Illuminate\Support\Facades\Mail; |
||
| 10 | |||
| 11 | class ContactController extends Controller |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Returns a view with the contact form |
||
| 15 | * |
||
| 16 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 17 | */ |
||
| 18 | public function show() |
||
| 19 | { |
||
| 20 | return view('contacts.create'); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Validates and submits a new contact form. |
||
| 25 | * Sends an e-mail address if all went as expected. |
||
| 26 | * |
||
| 27 | * @param Request $request |
||
| 28 | * @return \Illuminate\Http\RedirectResponse |
||
| 29 | */ |
||
| 30 | public function store(Request $request) |
||
| 31 | { |
||
| 32 | $data = $request->validate([ |
||
| 33 | 'name' => 'required|string|max:60', |
||
| 34 | 'email' => 'required|email', |
||
| 35 | 'message' => 'required|string|max:2000', |
||
| 36 | ]); |
||
| 37 | |||
| 38 | $name = $request->get('name'); |
||
| 39 | $contactMessage = ContactMessage::create($data); |
||
| 40 | $recipientAddress = config('mail.to')['address']; |
||
| 41 | |||
| 42 | if ($recipientAddress && (config('mail.status') || app()->environment(['production']))) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 43 | // Send e-mail to admin alerting about new contact |
||
| 44 | Mail::to($recipientAddress)->send(new ContactSubmitted($contactMessage)); |
||
| 45 | Log::info('New e-mail sent.'); |
||
| 46 | } |
||
| 47 | |||
| 48 | return redirect()->route('home') |
||
| 49 | ->with('success', "<p>Obrigado, $name!</p><p>A tua mensagem foi enviada com sucesso! Responderemos |
||
| 50 | assim que possível.</p>"); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |