$app->get("/brands", function () use($app) { return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll())); }); $app->post("/brands", function () use($app) { $brand = new Brand($_POST['name']); $brand->save(); return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll())); }); $app->post("/add_brand", function () use($app) { $store = Store::find($_POST['store_id']); $brand = Brand::find($_POST['brand_id']); $store->addBrand($brand); return $app['twig']->render('store.html.twig', array('store' => $store, 'stores' => Store::getAll(), 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); $app->get("/store/{id}/edit", function ($id) use($app) { $store = store::find($id); return $app['twig']->render('store_edit.html.twig', array('store' => $store)); }); $app->patch("/store/{id}", function ($id) use($app) { $store = Store::find($id); $brands = $store->getBrands(); $store->update($_POST['name']); return $app['twig']->render('store_edit.html.twig', array('store' => $store, 'brands' => $store->getBrands())); }); $app->delete("/store/{id}", function ($id) use($app) { $store = Store::find($id); $store->delete(); return $app['twig']->render("stores.html.twig", array('stores' => Store::getAll())); }); $app->post("/delete_stores", function () use($app) { $GLOBALS['DB']->exec("DELETE FROM stores_brands;");