Closed jesnagifto closed 8 months ago
protected function form() //form add/edit { $form = new Form(new Product()); $form->text('code',('Code')); $form->text('name',('Product Name'));
$form->select('catg_id', __('Category Name')) ->options(Category::all()->pluck('catg_name', 'id')) ->setWidth(4, 2) ->load('brand_id', '/admin/api/brands'); $form->multipleSelect('brand_id', __('Brand Name'))->setWidth(4, 2) ->options(function ($id) { $brand = Brands::find($id); if ($brand) { return [$brand->id => $brand->id]; } else { return []; } }); $form->currency('rate', __('Rate'))->symbol('₹')->setWidth(4, 2); $form->switch('active', __('Active'))->states(Constant::STATUS)->default(1);
$form->saved(function (Form $form) { $id = $form->model()->id; $catid = $form->model()->catg_id; $brandid = $form->model()->getOriginal('brand_id');
if ($id && is_array($brandid)) { foreach ($brandid as $followItem) { $brand = Brands::where('brand_name', $followItem)->first(); $tracks = new prdt_brand_category(); $tracks->prdt_id = $id; $tracks->category_id = $catid; $tracks->brands_id = $brand->id; $tracks->save(); } }
}); $form->builder()->isEditing(); return $form;
}
// Your controller
public function brands(Request $request) { $brand = $request->get('q'); $brandNames = Brand_category::with('brans')->where('category_id', $brand)->get()->pluck('brans.brand_name');
return $brandNames;
Description:
protected function form() //form add/edit { $form = new Form(new Product()); $form->text('code',('Code')); $form->text('name',('Product Name'));
$form->saved(function (Form $form) { $id = $form->model()->id; $catid = $form->model()->catg_id; $brandid = $form->model()->getOriginal('brand_id');
}); $form->builder()->isEditing(); return $form;
}
// Your controller
public function brands(Request $request) { $brand = $request->get('q'); $brandNames = Brand_category::with('brans')->where('category_id', $brand)->get()->pluck('brans.brand_name');
}
Steps To Reproduce: