]> _ Git - psq.git/commitdiff
Add contact form
authorLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 17 Sep 2020 12:03:12 +0000 (14:03 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 17 Sep 2020 12:03:12 +0000 (14:03 +0200)
app/ContactRequest.php [new file with mode: 0644]
app/Http/Controllers/ContactController.php [new file with mode: 0644]
app/Notifications/ContactRequest.php [new file with mode: 0644]
database/migrations/2020_09_17_103016_create_contact_requests_table.php [new file with mode: 0644]
resources/views/contact/index.blade.php [new file with mode: 0644]
routes/web.php

diff --git a/app/ContactRequest.php b/app/ContactRequest.php
new file mode 100644 (file)
index 0000000..79b8c2a
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Arr;
+
+/**
+ * Class ContactRequest
+ * @package App
+ * @property string $name
+ * @property string $organization
+ * @property string $email
+ * @property string $plan
+ * @property string $comments
+ * @property bool $quote_sent
+ * @property-read string $planString
+ *
+ */
+class ContactRequest extends Model
+{
+    protected $fillable = [
+        'name',
+        'organization',
+        'email',
+        'plan',
+        'comments',
+    ];
+
+    protected $casts = [
+        'quote_sent' => '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 (file)
index 0000000..a895965
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\ContactRequest;
+use Illuminate\Http\Request;
+
+class ContactController extends Controller
+{
+
+    public function index()
+    {
+        return view('contact.index');
+    }
+
+    public function store(Request $request)
+    {
+        $this->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 (file)
index 0000000..3f00c4a
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Notifications;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Notifications\Notification;
+
+class ContactRequest extends Notification
+{
+    use Queueable;
+
+    private \App\ContactRequest $contactRequest;
+
+    /**
+     * Create a new notification instance.
+     *
+     * @param \App\ContactRequest $contactRequest
+     */
+    public function __construct(\App\ContactRequest $contactRequest)
+    {
+        //
+        $this->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 (file)
index 0000000..43020eb
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateContactRequestsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('contact_requests', function (Blueprint $table) {
+            $table->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 (file)
index 0000000..4e1a573
--- /dev/null
@@ -0,0 +1,139 @@
+@extends('layouts.app')
+@inject('settings', \A17\Twill\Repositories\SettingRepository)
+
+@section('content')
+    <div class="container psq-not-registered">
+        <h1>Nous contacter</h1>
+
+        <div class="row justify-content-center">
+            <div class="col-md-8">
+                <div class="card">
+
+                    <div class="card-header">Demande d'abonnement</div>
+
+                    <div class="card-body">
+                        <form method="POST" action="{{ route('contact.store') }}">
+                            @csrf
+
+                            <div class="form-group row">
+                                <label for="name" class="col-md-4 col-form-label text-md-right">Nom complet</label>
+
+                                <div class="col-md-6">
+                                    <input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="full-name" autofocus>
+
+                                    @error('name')
+                                    <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                                    @enderror
+                                </div>
+                            </div>
+
+
+                            <div class="form-group row">
+                                <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
+
+                                <div class="col-md-6">
+                                    <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
+
+                                    @error('email')
+                                    <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                                    @enderror
+                                </div>
+                            </div>
+
+                            <div class="form-group row">
+                                <label for="organization" class="col-md-4 col-form-label text-md-right">{{ __('Employeur') }}</label>
+
+                                <div class="col-md-6">
+                                    <input id="organization" type="text" class="form-control @error('organization') is-invalid @enderror" name="organization" value="{{ old('organization') }}" required>
+
+                                    @error('organization')
+                                    <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                                    @enderror
+                                </div>
+                            </div>
+
+                            <div class="form-group row">
+                                <label for="comments" class="col-md-4 col-form-label text-md-right">Commentaires (facultatif)</label>
+
+                                <div class="col-md-6">
+                                    <textarea id="comments" rows="3" type="text" class="form-control @error('comments') is-invalid @enderror" name="comments" value="{{ old('comments') }}"></textarea>
+
+                                    @error('comments')
+                                    <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                                    @enderror
+                                </div>
+                            </div>
+
+                            <div class="form-group row">
+                                <label for="plan" class="col-12 col-form-label">
+                                    Dans le cadre d'un abonnement collectif, souhaitez-vous que l'abonnement concerne :
+                                </label>
+                                <div class="col-md-4">
+
+                                </div>
+
+                                <div class="col-md-6">
+
+                                    @foreach(\App\ContactRequest::PLANS as $key => $value)
+                                        <div class="custom-control custom-radio">
+                                          <input type="radio" id="plan_{{$key}}" name="plan" class="custom-control-input  @error('plan') is-invalid @enderror" value="{{$key}}" >
+                                          <label class="custom-control-label" for="plan_{{$key}}">{{$value}}</label>
+                                        </div>
+                                    @endforeach
+
+                                    @error('plan')
+                                    <span class="invalid-feedback d-block" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                                    @enderror
+                                </div>
+                            </div>
+
+
+
+                            <div class="form-group row">
+                                <div class="col-4"></div>
+                                <div class="col-8">
+                                    {!! ReCaptcha::htmlFormSnippet() !!}
+                                    @error(recaptchaFieldName())
+                                    <span class="invalid-feedback d-block" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                                    @enderror
+                                </div>
+                            </div>
+
+
+                            <div class="form-group row mb-0">
+                                <div class="col-md-6 offset-md-4">
+                                    <button type="submit" class="btn btn-primary">
+                                        Envoyer
+                                    </button>
+                                </div>
+                            </div>
+                            <div class="row mt-3">
+                                <div class="col-12">
+                                    <div class="alert alert-info">
+                                        Dès réception de ce formulaire, vous nous transmettrons un devis adapté à votre demande.
+                                    </div>
+                                </div>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+            </div>
+        </div>
+
+
+    </div>
+
+
+@endsection
index 9ac9f0181abd0143098952787e4e852403fb640f..524ecca0ebd40a78151451cef465a3f9a3b87d01 100644 (file)
@@ -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');