public function index() { $title = 'Kortingen'; $now = strtotime('now'); $discounts = Discount::where('from', '<=', $now)->where('to', '>=', $now)->paginate(20); return view('user.discounts.index', compact('title', 'discounts')); }
/** * Update the specified resource in storage. * * @param Requests\UpdateDiscountRequest $request * @param Company $company * @param Discount $discount * * @return \Illuminate\Http\Response */ public function update(Requests\UpdateDiscountRequest $request, Company $company, Discount $discount) { $input = $request->all(); $input['to'] = strtotime($input['to']); $input['from'] = strtotime($input['from']); // Updating discount $discount->update($input); if (!empty($request->file('file'))) { $name = uniqid(strtotime('now')); $ext = $request->file('file')->getClientOriginalExtension(); $file = $request->file('file'); $path = public_path('uploads/discounts/' . $name . '.' . $ext); // uploading image $img = Image::make($file)->save($path); $discount->image = $name . '.' . $ext; $discount->save(); } return redirect()->route('admin.company.profile', $company->id)->with('Success', 'Korting bijgewerkt'); }
public function search($input) { $query = Discount::query(); $columns = Schema::getColumnListing('discounts'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }