【问题标题】:Laravel : how to get the value when you submit/store into databaseLaravel:提交/存储到数据库时如何获取值
【发布时间】:2022-11-16 14:38:01
【问题描述】:

当我尝试提交这样的预订表格时:

How many book : 2
Name : a
email : a@gmail.com

email#1 : b@gmail.com

在数据库中:

ID : 1
Name : a
Email : a@gmail.com
Other email : NULL

ID : 2
Name : NULL
Email : NULL
Other email : b@gmail.com

我怎样才能使 ID 号 2 的名称和电子邮件的值不为空 但相反是

ID : 2
Name : a
Email : a@gmail.com
Other email : b@gmail.com

控制器:

$firstName = $booking->first_name;
        $lastName = $booking->last_name;
        foreach ($request->input('other_emails') as $email){
            Booking::create([
                'first_name'=>$firstName,
                'last_name'=>$lastName,
                'other_emails'=>$email
            ]);
            Mail::to($email)->send(new OthersEmail($isi_email1));
        }

该模型 :

protected $fillable = [
        'first_name',
        'last_name',
        'other_emails'    
    ];

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    您必须更新您的数据。

    Booking::where('ID',2)->update([
      'first_name'=>$firstName,
      'last_name'=>$lastName,
      'other_emails'=>$email
    ])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 2022-11-15
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 2021-07-20
      相关资源
      最近更新 更多