我正在使用http://laravel-admin.org/此扩展程序管理面板
我的控制器 class Related_productController扩展Controller { 使用ModelForm;
/**
* Index interface.
*
* @return Content
*/
public function index()
{
return Admin::content(function (Content $content) {
$content->header('header');
$content->description('description');
$content->body($this->grid());
});
}
/**
* Edit interface.
*
* @param $id
* @return Content
*/
public function edit($id)
{
return Admin::content(function (Content $content) use ($id) {
$content->header('header');
$content->description('description');
$content->body($this->form()->edit($id));
});
}
/**
* Create interface.
*
* @return Content
*/
public function create()
{
return Admin::content(function (Content $content) {
$content->header('header');
$content->description('description');
$content->body($this->form());
});
}
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Admin::grid(Related_product::class, function (Grid $grid) {
$grid->id('ID')->sortable();
$grid->column('related_id');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Admin::form(Related_product::class, function (Form $form) {
$form->display('id', 'ID');
$form->select('product_id')->options(product::all()->pluck('id', 'id'));
$form->multipleSelect('related_id')->options(product::all()->pluck('productname', 'productname'));
});
}
}
我的模特
class Related_product extends Model
{
protected $table = 'related_product';
public $timestamps = false;
public function setRelated_productAttribute($related_id)
{
if (is_array($related_id))
{
$this->attributes['related_id'] = implode(',', $related_id);
}
}
当我选择multiselect并提交数据时,它显示错误,如
QueryException在Connection.php第664行中:
数组转换为字符串(SQL:插入related_product
(product_id
,related_id
)值(48,))