コード例 #1
0
 public function edit($product_id)
 {
     //edit the product
     $productsCount = 0;
     $products = Auth::user()->products;
     $product = $products->find($product_id);
     $categories = Category::all();
     // return redirect()->route('user::products')->with(compact('productsCount', 'products', 'categories'));
     return view('add-product', compact('productsCount', 'products', 'categories'))->withUser(Auth::user());
 }
コード例 #2
0
 public function confirmApproval(CategoryRequest $request, AppMailer $mailer, $id)
 {
     $category = Category::find($id);
     if (!$category) {
         return redirect()->back()->withErrors(['Category not found to approve!']);
     }
     if (!$request->has('confirmation-select')) {
         return redirect()->back()->withErrors(['Invalid request of approval confirmation!']);
     }
     switch ($request->input('confirmation-select')) {
         case 'approve':
             $category->status = 'APPROVED';
         case 'reject':
             $category->status = 'REJECTED';
         case 'remove':
             $category->status = 'REMOVED';
     }
     // if($request->input('confirmation-select') == 'approve')
     //     $category->status = 'APPROVED';
     // if($request->input('confirmation-select') == 'reject')
     //     $category->status = 'REJECTED';
     if (!$category->save()) {
         return redirect()->back()->withErrors(['Failed to confirm category approval!']);
     }
     flash()->success('Your have ' . strtolower($category->getStatus()) . ' category (' . $category->category_name . ').');
     // Sends approval mail to users has a single product
     $data['type'] = Category::class;
     $data['status'] = $category->getStatus();
     $data['item_name'] = $category->category_name;
     $data['created_at'] = $category->created_at;
     foreach ($category->products->unique('user_id') as $product) {
         $mailer->sendEmailForApprovalNotificationTo($product->user, $data);
     }
     return redirect()->back();
 }