/** * @POST("/uploading_data") * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function uploading_data(Request $request) { $photos = $request->input('photos'); $category_id = $request->input('category_id'); if ($request->input('shop_id')) { $shop_id = $request->input('shop_id'); $shop = Shops::find($shop_id); if ($shop && !$shop->canAddItem()) { return redirect()->route('shops.my'); } foreach ($photos as $photo) { foreach ($photo as $item) { $attachment = new Attachment(); $attachment->name = $item['aid']; $attachment->path = $item['src_big']; $attachment->url = $item['src_big']; $attachment->save(); $shop_item = new ShopItems(); $shop_item->name = 'Название'; $shop_item->description = $item['text']; $shop_item->shop_id = $shop_id; $shop_item->category_id = $category_id; if ($attachment) { $shop_item->attachment()->associate($attachment); } $shop_item->save(); } } } }
/** * @param $id * @return \Illuminate\Http\RedirectResponse */ public function block($id) { $shop = Shops::find($id); $input = \Request::only('blocked')['blocked']; $shop->blocked = $input; $shop->update(); return redirect()->route('admin.shops.index'); }
/** * Store a newly created resource in storage. * * @param ShopItemsRequest $request * @return Response */ public function store(ShopItemsRequest $request) { $shop = Shops::find($request->shop_id); if ($shop && !$shop->canAddItem()) { return redirect()->route('shops.my'); } $request->file(); $file = ImageUploadFacade::attachmentUpload($request->file('attachment'), new Attachment(), 'shop_items'); $item = new ShopItems(); $item->fill($request->all()); if ($file) { $item->attachment()->associate($file); } $item->save(); return redirect()->route('shops.show', ['id' => $request->shop_id]); }
/** * Send orders * @Post("/cart/send_order", as="order.send") */ public function send(Request $request) { $client = $request->user; $cart = $request->cart; $totalSum = 0; foreach ($cart as $item) { $itemInShop = ShopItems::find($item['_id']); $totalSum += $itemInShop->price * $item['_quantity']; $items[$item['_data']['partner']][] = ['id' => $itemInShop->id, 'name' => $itemInShop->name, 'price' => $itemInShop->price, 'quantity' => $item['_quantity']]; } foreach ($items as $id => $positions) { $data = ['items' => $positions, 'client' => $client, 'totalSum' => $totalSum]; $shop = Shops::find($id); \Mail::send('shops::emails.order', $data, function ($message) use($shop) { $message->from('*****@*****.**', 'Новый заказ'); $message->to($shop->profile->email)->subject('Новый заказ'); }); } }
/** * @POST("shops/get_photos", middleware="auth") * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function getPhotos(Request $request) { if ($request->s_id) { $shop_id = $request->s_id; \Session::put('shop_id', $shop_id); } else { $s_id = \Session::get('shop_id'); $shop = Shops::find($s_id); if ($shop && !$shop->canAddItem()) { return redirect()->route('shops.my'); } $file = ImageUploadFacade::attachmentUpload($request->file("file"), new Attachment(), 'shop_items'); $item = new ShopItems(); $item->name = 'Название'; $item->description = 'Описание'; $item->shop_id = $s_id; if ($file) { $item->attachment()->associate($file); } $item->save(); } //return redirect()->route('shops.show', ['id'=>$request->id]); }