问题描述
在尝试创建管理员可以在使用Orchid管理平台保存类别之前创建类别和选择产品的位置时,类别可以很好地保存,但是分配给该类别的产品不会保存,也没有任何错误。这是我的代码
这是我的查询
public $exists = false;
/**
* Query data.
*
* @return array
*/
public function query(Category $category,Product $product): array
{
$this->exists = $category->exists;
if($this->exists){
$this->name = 'Edit Category';
}
return [
'category' => $category,'product' => $product
];
}
这是我的命令
/**
* Button commands.
*
* @return Action[]
*/
public function commandBar(): array
{
return [
Button::make('Create Category')
->icon('icon-pencil')
->method('createOrUpdate')
->canSee(!$this->exists),Button::make('Update')
->icon('icon-note')
->method('createOrUpdate')
->canSee($this->exists),Button::make('Remove')
->icon('icon-trash')
->method('remove')
->canSee($this->exists),];
}
这是我的布局
/**
* Views.
*
* @return Layout[]
*/
public function layout(): array
{
return [
Layout::rows([
Input::make('category.name')
->type('text')
->required()
->title('Category Name')
->placeholder('Enter category name')
->help('Please enter a short and descriptive name for your customers'),Input::make('category.slug')
->type('text')
->required()
->title('Category Slug')
->placeholder('Category slug')
->help('Please enter a title name for this category'),Relation::make('category.product.')
->title('choose a products')
->placeholder('Search ...')
->required()
->multiple()
->fromModel(Product::class,'name')
])
];
}
这是我的方法
/**
* @param Category $category
* @param Product $product
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createOrUpdate(Category $category,Request $request,Product $product)
{
$category->fill($request->get('category'))->save();
Alert::success('Your category was successfully created.');
return redirect()->route('platform.category.list');
}
public function remove(Category $category)
{
$category->delete()
? Alert::success('Category was successfully deleted!.')
: Alert::warning('Whooops! Something went wrong!')
;
return redirect()->route('platform.category.list');
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)