我正在接受Jeffry方式教程我从本教程LInK完成了所有工作 当我从我的商店功能插入数据时,我得到如下错误:
ErrorException in helpers.php line 747:
preg_replace(): Parameter mismatch, pattern is a string while replacement is an array
in helpers.php line 747
at HandleExceptions->handleError('2', 'preg_replace(): Parameter mismatch, pattern is a string while replacement is an array', 'C:\xampp\htdocs\elixir\vendor\laravel\framework\src\Illuminate\Support\helpers.php', '747', array('search' => '\?', 'replace' => array('1', '', '1', '1', '', '1', '', array('1', '2'), '', '', '', '', '', '', '', '0', '', '', '1', '2016-08-18 18:15:46', '2016-08-18 18:15:46'), 'subject' => 'insert into `psl_calls` (`branch_id`, `vessel_name`, `port_id`, `jetty_id`, `voyage_no`, `principal_id`, `reference_no`, `purposes`, `eta_estimate_time`, `etb_estimate_time`, `etc_estimate_time`, `etd_estimate_time`, `previous_port_id`, `next_port_id`, `employee_id`, `quality_rating`, `cancel_remark`, `no_cost_time_remark`, `user_id`, `updated_at`, `created_at`) values (1, , 1, 1, , 1, , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', 'value' => array('1', '2')))
我的控制器功能如下:
public function store(Request $request)
{
$input = $request->all();
$input['user_id'] = \Auth::id();
$call = PslCall::create($input);
$call->purposes()->attach($request->input('purposes'));
// return Redirect::to('/calls');
}
我的PslCall模型:
public function purposes()
{
return $this->belongsToMany('App\Models\PslPurpose')->withTimestamps();
}
我有一个数据透视表调用:
Schema::create('psl_call_psl_purpose', function (Blueprint $table) {
$table->integer('psl_call_id')->unsigned()->index();;
$table->foreign('psl_call_id')->references('id')->on('psl_calls')->onDelete('cascade');
$table->integer('psl_purpose_id')->unsigned()->index();;
$table->foreign('psl_purpose_id')->references('id')->on('psl_purposes')->onDelete('cascade');
$table->timestamps();
});
答案 0 :(得分:0)
$call->purposes()->attach(['field_name'=> $request->input('purposes')]);
// return Redirect::to('/calls');
将field_name
替换为目的表的列名