From 159627a1160f3a5bf84fdaecfbb4d13c39cecdf6 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Thu, 17 Sep 2020 14:03:12 +0200 Subject: [PATCH] Add contact form --- app/ContactRequest.php | 51 +++++++ app/Http/Controllers/ContactController.php | 42 ++++++ app/Notifications/ContactRequest.php | 78 ++++++++++ ...7_103016_create_contact_requests_table.php | 38 +++++ resources/views/contact/index.blade.php | 139 ++++++++++++++++++ routes/web.php | 2 + 6 files changed, 350 insertions(+) create mode 100644 app/ContactRequest.php create mode 100644 app/Http/Controllers/ContactController.php create mode 100644 app/Notifications/ContactRequest.php create mode 100644 database/migrations/2020_09_17_103016_create_contact_requests_table.php create mode 100644 resources/views/contact/index.blade.php diff --git a/app/ContactRequest.php b/app/ContactRequest.php new file mode 100644 index 0000000..79b8c2a --- /dev/null +++ b/app/ContactRequest.php @@ -0,0 +1,51 @@ + 'boolean' + ]; + + public const PLANS = [ + 1 => 'un forfait minimum de 1 à 10 personnes', + 2 => 'de 1 à 20 personnes', + 3 => "un nombre illimité de salariés dans l'entreprise" + ]; + + + /** + * @return string + */ + public function getPlanStringAttribute(): string + { + return Arr::get(self::PLANS, $this->plan, 'forfait inconnu'); + } + + + +} diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php new file mode 100644 index 0000000..a895965 --- /dev/null +++ b/app/Http/Controllers/ContactController.php @@ -0,0 +1,42 @@ +validate($request, [ + 'name' => ['required', 'string', 'max:255'], + 'organization' => ['required', 'string', 'max:255'], + 'email' => [ + 'required', + 'string', + 'email', + 'max:255', + ], + 'plan' => 'required', + recaptchaFieldName() => recaptchaRuleName(), + + ]); + + $contactRequest = new ContactRequest($request->all()); + $contactRequest->save(); + \Notification::route('mail', 'olivier.robichon@prescription-quotidien.com') + ->notify(new \App\Notifications\ContactRequest($contactRequest)); + + \Session::flash('message', "Votre demande a bien été prise en compte, nous reviendrons vers vous dans les plus brefs délais. Merci de l'intérêt que vous portez à Prescription Santé - Le Quotidien !"); + return redirect()->route('home'); + } + + +} diff --git a/app/Notifications/ContactRequest.php b/app/Notifications/ContactRequest.php new file mode 100644 index 0000000..3f00c4a --- /dev/null +++ b/app/Notifications/ContactRequest.php @@ -0,0 +1,78 @@ +contactRequest = $contactRequest; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + $message = (new MailMessage) + ->subject("[{$this->contactRequest->organization}] Demdande de contact de {$this->contactRequest->name}") + ->greeting('Bonjour, ') + ->line("**{$this->contactRequest->name}** de la société **{$this->contactRequest->organization}** à envoyé une demande de contact.") + ->line("La demande d'abonnement concerne **{$this->contactRequest->planString}**"); + + if(null !== $comments = $this->contactRequest->comments) { + $message->line('Un commentaire à été joint à la demande :'); + foreach(explode(PHP_EOL, $comments) as $line) { + $line = trim($line); + $message->line("*$line*"); + } + + } + + return $message + ->line("**{$this->contactRequest->name}** à demandé à être contacté à l'adresse suivante : [{$this->contactRequest->email}](mailto:{$this->contactRequest->email})"); + + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/database/migrations/2020_09_17_103016_create_contact_requests_table.php b/database/migrations/2020_09_17_103016_create_contact_requests_table.php new file mode 100644 index 0000000..43020eb --- /dev/null +++ b/database/migrations/2020_09_17_103016_create_contact_requests_table.php @@ -0,0 +1,38 @@ +id(); + $table->string('name'); + $table->string('organization'); + $table->string('email'); + $table->string('plan'); + $table->text('comments')->nullable(); + $table->boolean('quote_sent')->default(0); + $table->timestamps(); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('contact_requests'); + } +} diff --git a/resources/views/contact/index.blade.php b/resources/views/contact/index.blade.php new file mode 100644 index 0000000..4e1a573 --- /dev/null +++ b/resources/views/contact/index.blade.php @@ -0,0 +1,139 @@ +@extends('layouts.app') +@inject('settings', \A17\Twill\Repositories\SettingRepository) + +@section('content') +
+

Nous contacter

+ +
+
+
+ +
Demande d'abonnement
+ +
+
+ @csrf + +
+ + +
+ + + @error('name') + + {{ $message }} + + @enderror +
+
+ + +
+ + +
+ + + @error('email') + + {{ $message }} + + @enderror +
+
+ +
+ + +
+ + + @error('organization') + + {{ $message }} + + @enderror +
+
+ +
+ + +
+ + + @error('comments') + + {{ $message }} + + @enderror +
+
+ +
+ +
+ +
+ +
+ + @foreach(\App\ContactRequest::PLANS as $key => $value) +
+ + +
+ @endforeach + + @error('plan') + + {{ $message }} + + @enderror +
+
+ + + +
+
+
+ {!! ReCaptcha::htmlFormSnippet() !!} + @error(recaptchaFieldName()) + + {{ $message }} + + @enderror +
+
+ + +
+
+ +
+
+
+
+
+ Dès réception de ce formulaire, vous nous transmettrons un devis adapté à votre demande. +
+
+
+
+
+
+
+
+ + +
+ + +@endsection diff --git a/routes/web.php b/routes/web.php index 9ac9f01..524ecca 100644 --- a/routes/web.php +++ b/routes/web.php @@ -70,6 +70,8 @@ Route::domain(env('CLIENT_DOMAIN_NAME'))->group(function() { Route::get('podcasts', 'PodcastController@index'); Route::get('pas-encore-inscrit', 'Auth\NotRegisteredYet@index')->name('not-registered'); + Route::get('contact', 'ContactController@index')->name('contact.index'); + Route::post('contact', 'ContactController@store')->name('contact.store'); Route::prefix('actus-labos')->group(function() { Route::get('', 'ActuLabosController@index')->name('actus-labos.index'); -- 2.39.5