diff --git a/app/Http/Controllers/Bo/MagasinsController.php b/app/Http/Controllers/Bo/MagasinsController.php index d16f32c..9c450d1 100644 --- a/app/Http/Controllers/Bo/MagasinsController.php +++ b/app/Http/Controllers/Bo/MagasinsController.php @@ -40,6 +40,7 @@ class MagasinsController extends Controller { $request->validate([ 'name' => 'required|string|max:255', + 'email' => 'required|email:rfc,dns,spoof|max:255', 'address' => 'required|string|max:255', 'postcode' => 'required', 'city' => 'required|string|max:255', @@ -73,6 +74,7 @@ class MagasinsController extends Controller { $request->validate([ 'name' => 'required|string|max:255', + 'email' => 'required|email:rfc,dns,spoof|max:255', 'address' => 'required|string|max:255', 'postcode' => 'required', 'city' => 'required|string|max:255', diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 83f63c4..038c69b 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -25,11 +25,12 @@ class ContactController extends Controller // @phpcs:enable $status = $request->session()->get('status'); - // 1er magasin en base pour le moment - $magasin = Magasin::first(); + $magasin = Magasin::first(); + $magasins = Magasin::all(); + $content = Content::where('key', 'contact')->first(); - return view('contact', compact('status', 'magasin', 'content')); + return view('contact', compact('status', 'magasins', 'magasin', 'content')); } /** @@ -42,12 +43,20 @@ class ContactController extends Controller { $data = $request->all(); - $toMailSetting = Setting::where('key', 'send_contact_mail_to')->first(); - if (empty($toMailSetting->value)) { - $toMail = config('mail.from.address'); + /** @var Magasin|null */ + $shop = Magasin::where('name', $request->shop)->first(); + + if ($shop) { + $toMail = $shop->email; } else { - $toMail = $toMailSetting->value; + $toMailSetting = Setting::where('key', 'send_contact_mail_to')->first(); + if (empty($toMailSetting->value)) { + $toMail = config('mail.from.address'); + } else { + $toMail = $toMailSetting->value; + } } + // Envoi du mail d'alerte. Mail::to($toMail)->send(new SendContactMail($request)); diff --git a/app/Http/Requests/ContactFormRequest.php b/app/Http/Requests/ContactFormRequest.php index 9e99e13..0fb32b9 100644 --- a/app/Http/Requests/ContactFormRequest.php +++ b/app/Http/Requests/ContactFormRequest.php @@ -27,6 +27,7 @@ class ContactFormRequest extends FormRequest 'last_name' => 'required|min:2', 'first_name' => 'required|min:2', 'email' => 'required|email:rfc,dns,spoof', + 'shop' => 'sometimes', 'subject' => 'required|min:2', 'order_ref' => 'sometimes', 'message' => 'required|min:20|max:1900', diff --git a/app/Models/Magasin.php b/app/Models/Magasin.php index ce7c754..596e2bb 100644 --- a/app/Models/Magasin.php +++ b/app/Models/Magasin.php @@ -15,7 +15,7 @@ class Magasin extends Model * @var array */ protected $fillable = [ - 'name', 'address', 'postcode', 'city', 'phone', + 'name', 'email', 'address', 'postcode', 'city', 'phone', 'latitude', 'longitude', 'gmaps_placeid', 'gmaps_embed_href', 'gmaps_link_href', ]; diff --git a/database/migrations/2021_04_21_165607_create_magasins_table.php b/database/migrations/2021_04_21_165607_create_magasins_table.php index 1454099..2028ff6 100644 --- a/database/migrations/2021_04_21_165607_create_magasins_table.php +++ b/database/migrations/2021_04_21_165607_create_magasins_table.php @@ -17,6 +17,7 @@ class CreateMagasinsTable extends Migration Schema::create('magasins', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->string('email'); $table->string('address'); $table->string('postcode'); $table->string('city'); diff --git a/database/seeders/MagasinsSeeder.php b/database/seeders/MagasinsSeeder.php index 54ffe4f..d6f4e4a 100644 --- a/database/seeders/MagasinsSeeder.php +++ b/database/seeders/MagasinsSeeder.php @@ -14,13 +14,14 @@ class MagasinsSeeder extends Seeder */ public function run() { - $shop = new Magasin(); - $shop->name = 'Point de retrait'; - $shop->address = 'l\'adresse'; - $shop->postcode = '72000'; - $shop->city = 'Le Mans'; + $shop = new Magasin(); + $shop->name = 'Point de retrait'; + $shop->email = 'adresse@domaine.fr'; + $shop->address = 'l\'adresse'; + $shop->postcode = '72000'; + $shop->city = 'Le Mans'; $shop->gmaps_embed_href = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d5338.425979915083!2d0.1977634707405403!3d48.00959481914027!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47e288cfcdc1a263%3A0x7acf6d8dc923c25a!2zQ2l0w6kgUGxhbnRhZ2Vuw6p0!5e0!3m2!1sfr!2sfr!4v1619612657653!5m2!1sfr!2sfr"; - $shop->gmaps_link_href = 'https://goo.gl/maps/sxuj7FevRSHsDb8MA'; + $shop->gmaps_link_href = 'https://goo.gl/maps/sxuj7FevRSHsDb8MA'; $shop->save(); } } diff --git a/resources/views/bo/magasins/create.blade.php b/resources/views/bo/magasins/create.blade.php index e1cf8fc..849b3c6 100644 --- a/resources/views/bo/magasins/create.blade.php +++ b/resources/views/bo/magasins/create.blade.php @@ -22,6 +22,10 @@ +