public function __construct(App $app) { parent::__construct($app); $this->tableProduct = $this->getModel()->getTableName(); $this->tableSku = Sku::getTableName(); $this->tableSkuImages = Sku\Image::getTableName(); $this->tableSupplier = Supplier::getTableName(); $this->tableCategory = Category::getTableName(); $this->tableProductCategory = ProductCategory::getTableName(); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('products_categories')->truncate(); \App\Models\Product\Category::create(['name' => 'Televizoare', 'slug' => 'televizoare']); }
/** * Remove the specified resource from storage. * * @param int $id * * @return \Illuminate\Http\Response */ public function destroy($id) { $category = Category::with('products')->find($id); if ($category && $category->products->isEmpty()) { if ($category->delete()) { return response()->json(true); } } return response()->json('informatia nu s-a putut sterge', 500); }
public function testAddingCategories() { $categories = \App\Models\Product\Category::leavesOnly()->inRandomOrder()->take(2)->get(); $this->visitCategoriesPage(); foreach ($this->product->categories as $category) { $this->uncheckMulti('category-' . $category->id); } foreach ($categories as $category) { $this->checkMulti('category-' . $category->id); } $this->press('提交')->see('修改成功'); foreach ($categories as $category) { $this->seeIsChecked('category-' . $category->id); $this->seeInDatabase('category_product', ['product_id' => $this->product->id, 'category_id' => $category->id]); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return Category::get(); }