実現したいこと
姓と名を分けたフォームからデータを受け取り、それをmysqlのカラムには姓と名を合わせてfullname
としてcreateしたいです。
前提
勉強の一環でlaravelを使い、お問い合わせフォームを作っています。
該当のソースコード
index.blade.php
1<form class="form" action="contacts/confirm" method="post"> 2 <div class="form__input--text"> 3 <input type="text" name="last_name" value="{{ old('last_name') }}" /> 4 <input type="text" name="first_name" value="{{ old('first_name') }}" /> 5 </div> 6</form>
confirm.blade.php
1<form class="form" action="/contacts" method="post"> 2 <td class="confirm-table__text"> 3 <input type="text" name="last_name" value="{{ $contact['last_name'] }}" readonly /> 4 <input type="text" name="first_name" value="{{ $contact['first_name'] }}" readonly /> 5 </td> 6</form> 7
ContactController.php
1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Request; 6use App\Models\Contact; 7 8class ContactController extends Controller 9{ 10 public function index() 11 { 12 return view('index'); 13 } 14 public function confirm(Request $request) 15 { 16 $contact = $request->only(['last_name', 'first_name']); 17 18 return view('confirm', ['contact' => $contact]); 19 } 20 public function store(Request $request) 21 { 22 //ここで処理? 23 $contact = $request->only(['']); 24 Contact::create($contact); 25 26 return view('thanks'); 27 } 28}
聞きたいこと
index.blade.phpから受け取った値をcontrollerでconfirm.blade.phpに渡し、
確認した後にDBへcreateしたいと思っています。
その場合controllerのstore関数の所で、lastnameとfirstnameの結合を行うのかと考えたのですが
その方法を調べてもわからなかったので、ご教授いただきたいです。
調査したこと・試したこと
色々と用語を変えて検索しましたが、アクセサとミューテタくらいしか近いものが見つかりませんでした。
ミューテタをうまく利用すればと考えましたが、わかりませんでした。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/11/12 07:15