laravel9 問い合わせフォームradioボタンがMailableクラスでUndefined array key radioとなる。

Laravel9で問い合わせフォームを作成しました。

問い合わせフォーム内に以下のradioボタンがあります。

contact.blade.php

<td class="form"> <div class="form-radio"> <input class="input" type="radio" name="radio" id="contact" value="お問合せ" {{ old('radio') === 'お問合せ' ? 'checked' : '' }}/> <label class="label" for="contact">お問合せ</label> </div> <div class="form-radio"> <input class="input" type="radio" name="radio" id="quote" value="お見積依頼" {{ old('radio') === 'お見積依頼' ? 'checked' : '' }}/> <label class="label" for="quote">お見積依頼</label> </div> <div class="form-radio-"> <input class="input" type="radio" name="radio" id="other" value="その他" {{ old('radio') === 'その他' ? 'checked' : '' }}/> <label class="label" for="other">その他</label> </div> </td>

問い合わせフォームを入力 -> 入力確認画面(confirm.blade.php
)では以下のコードでtype="radio"のvalueが取得できています。

confirm.blade.php

<p> {{$inputs['radio']}}</p>

確認画面 -> Mailableクラスを使用して問い合わせを送信するのに、app/Mail/ContactsSendmail.php を作成。以下のように記述しました。

ContactsSendmail.php

<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; class ContactsSendmail extends Mailable { use Queueable, SerializesModels; // プロパティを定義 private $radio; private $company_name; private $contact_name; private $kana; private $tell; private $zip; private $add; private $message; /** * Create a new message instance. * * @return void */ public function __construct($inputs) { // コンストラクタでプロパティに値を格納 $this->radio = $inputs['radio']; $this->company_name = $inputs['company_name']; $this->contact_name = $inputs['contact_name']; $this->kana = $inputs['kana']; $this->tell = $inputs['tell']; $this->zip = $inputs['zip']; $this->add = $inputs['add']; $this->email = $inputs['email']; $this->body = $inputs['body']; } /** * Build the message. * * @return $this */ public function build() { // メールの設定 return $this ->from('hello@example.com') ->subject('自動送信メール') ->view('contact.mail') ->with([ 'radio' => $this->radio, 'company_name' => $this->company_name, 'contact_name' => $this->contact_name, 'kana' => $this->kana, 'tell' => $this->tell, 'zip' => $this->zip, 'add' => $this->add, 'email' => $this->email, 'body' => $this->body, ]); } }

しかし、以下の箇所で「Undefined array key "radio"」のエラーが出ています。

ContactsSendmail.php

// コンストラクタでプロパティに値を格納 $this->radio = $inputs['radio'];

配列から存在しないkeyを指定していると「Undefined array key "XXX"」というエラーになるようなのですが、入力確認画面では以下のコードでtype="radio"のvalueが取得、表示されているのに、Mailableクラスを使用して問い合わせを送信する際にはなぜエラーになってしまうのでしょうか?

コメントを投稿

0 コメント