public function run() { DB::table('bundles')->delete(); $collection = [['name' => 'Small', 'description' => 'Left Wing and Avionics', 'color' => '#3f8dc6', 'cost' => 75000, 'value' => 200000], ['name' => 'Large', 'description' => 'Left Wing, Right Wing and Avionics', 'color' => '#c6783f', 'cost' => 100000, 'value' => 300000], ['name' => 'Super Size', 'description' => 'Left Wing, Right, Avionics and Interior', 'color' => '#783fc6', 'cost' => 150000, 'value' => 1000000]]; foreach ($collection as $record) { Bundle::create($record); } }
public function update($id) { // save updated $record = $this->records->find($id); if (!$record) { Bundle::create(Input::all()); return $this->respond($record); } $record->fill(Input::all())->save(); return $this->respond($record); }
/** * Find item in cart, * @param $id * @param $type * @return mixed */ public function findItem($id, $type) { $query = $this; if ($type == self::TYPE_BOOK) { $query = Book::join('prices', function ($query) use($id) { $query->on('prices.item_id', '=', 'books.id')->where('books.id', '=', $id)->where('prices.type', '=', self::TYPE_BOOK); })->select(['books.id', 'books.title', 'books.teaser', 'prices.minimumprice', 'prices.suggestedprice', DB::raw('1 as type'), DB::raw('CONCAT("[\\"", books.diravatar, "\\"]") as avatar')]); } else { if ($type == self::TYPE_BUNDLE) { $query = Bundle::join('prices', function ($query) { $query->on('prices.item_id', '=', 'bundles.id')->where('prices.type', '=', self::TYPE_BUNDLE); })->join('book_bundle', function ($query) { $query->on('book_bundle.bundle_id', '=', 'bundles.id')->where('accepted', '=', 1); })->join('books', function ($query) { $query->on('books.id', '=', 'book_bundle.book_id'); })->groupBy('bundles.id')->select(['bundles.id', 'bundles.title', 'bundles.description as teaser', 'prices.minimumprice', 'prices.suggestedprice', DB::raw('2 as type'), DB::raw('CONCAT("[\\"", "books.diravatar", "\\"]") as avatar')]); } } return $query->first(); }