简体   繁体   English

使用SQL将数据插入Laravel Controller中的表的两列中

[英]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.

相关问题 如何使用 DB::Tranactions 将数据插入单个控制器中的两个表 - how to insert data to two table in a single controller using DB::Tranactions 在 pivot 表中插入数据 Controller Laravel 8 - Insert data in pivot table Controller Laravel 8 将 CSV 文件导入 Laravel 控制器并将数据插入到两个表中 - Import CSV file to Laravel controller and insert data to two tables 如何从单个控制器将数据插入到 Laravel 中的多个表中? - How to insert data into multiple table in laravel from single Controller? 如何在Laravel中将数据插入具有相同模型列的数据透视表中? - How to insert data into a pivot table with columns belonging to same model in Laravel? 无法插入行-Laravel中的数据表上缺少列 - Unable to insert row - columns missing on data table in Laravel 使用 CodeIgniter 将数组数据插入到两个表中 - insert array data into two table using CodeIgniter 想要使用CakePhp中的一个控制器文件在两个表中插入数据 - Want to insert data in two tables using one controller file in CakePhp 如何在 laravel controller 中使用两个 foreach 循环时传递数据 - How to pass the data while using two foreach loop in laravel controller 尝试使用外键在laravel中一次将数据插入两个表 - trying to insert data into two tables at once in laravel using foreign key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM