Php 我正在尝试使用兰花平台创建产品类别
我正在尝试创建一个管理员可以创建类别并在使用兰花管理平台保存类别之前选择产品的位置,该类别保存良好,但分配给该类别的产品未保存,并且没有任何错误。这是我的密码 这是我的问题Php 我正在尝试使用兰花平台创建产品类别,php,laravel,web-applications,web-development-server,laravel-7.x,Php,Laravel,Web Applications,Web Development Server,Laravel 7.x,我正在尝试创建一个管理员可以创建类别并在使用兰花管理平台保存类别之前选择产品的位置,该类别保存良好,但分配给该类别的产品未保存,并且没有任何错误。这是我的密码 这是我的问题 public $exists = false; /** * Query data. * * @return array */ public function query(Category $category, Product $product): array { $this->exists = $ca
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');
}
}