[英]Insert data into two columns of a table in Laravel Controller using sql
I have been trying to insert data using query into two columns of a table but there's something missing that its not sending data in the other column named booking_code. 我一直在尝试使用查询将数据插入到表的两列中,但是缺少一些内容,即它没有在名为booking_code的另一列中发送数据。
It is inserting the booking_id into the table but not booking_code. 它是在表中插入booking_id,而不是booking_code。
Here is the controller: 这是控制器:
public function store(CreatePaymentRequest $request) { $input = $request->all(); $booking_id = $request->booking_id; $booking_code = Booking::find($booking_id)->booking_code; $this['booking_code'] = $booking_code; $payment = $this->paymentRepository->create($input); Flash::success('Payment saved successfully.'); return redirect(route('admin.payments.index')); }
Please have a look at the Relevant Documentation Pages 请查看相关文档页面
You may also use the create method to save a new model in a single line.
您也可以使用create方法将新模型保存在一行中。 The inserted model instance will be returned to you from the method.
插入的模型实例将从该方法返回给您。 However, before doing so, you will need to specify either a fillable or guarded attribute on the model, as all Eloquent models protect against mass-assignment by default.
但是,在执行此操作之前,您将需要在模型上指定可填充或受保护的属性,因为默认情况下,所有Eloquent模型都可以防止大规模分配。
That means that you have to set, in Model, which fields you will allow to be "mass-assigned". 这意味着您必须在“模型”中设置允许“质量分配”的字段。
In your case, it will looks something like 就您而言,它看起来像
class Booking extends Model
(...)
{
protected $fillable = ['booking_code', (...)];
}
(...)
In the code you provided though, I can't see how you build an $input
variable so maybe the issue is there? 在您提供的代码中,我看不到如何构建
$input
变量,所以问题可能出在那儿? Maybe it's just some typo. 也许只是拼写错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.