/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update($id) { $note = Note::find($id); $rules = ['title' => 'required|min:2', 'body_text' => 'required|min:5|max:10000', 'is_public' => 'required']; if (Auth::User()->id != $note->user_id) { Flash::warning('You are not authorized to do that'); return redirect()->route('home'); } $validator = \Validator::make(Input::only('title', 'body_text', 'is_public'), $rules); if ($validator->fails()) { return redirect()->back()->withInput()->withErrors($validator); } $note->title = Input::get('title'); $note->body_text = Input::get('body_text'); $note->is_public = Input::get('is_public'); $note->collection_id = null; if (Input::get('collection') > 0) { $collection = Collection::find(Input::get('collection')); $collection->notes()->save($note); } $note->save(); Flash::info('Note Updated!'); return redirect()->route('notes.show', $note->id); }
protected function collectionStore(Request $request, $id = null) { if (Auth::check()) { if ($id) { $collection = Collection::find($id); } else { $collection = new Collection(); } $collection->name = $request->input('collection_name'); $collection->slug = str_slug($request->input('collection_name'), "-"); try { $collection->save(); return redirect('/home/collections'); } catch (\Illuminate\Database\QueryException $e) { return $e->getMessage(); } } else { return 'No auth'; } }
public function showWithProducts($id) { $coll = Collection::find($id); $collection = CollectionProduct::where('collection_id', '=', $id)->get(); // dd($collection) ; $collection_list = []; $creator = $coll->created_by; $creator = User::find($creator); foreach ($collection as $pro) { $product_id = $pro->product_id; $product = Product::find($product_id); $product = Product::add_created_by_and_category($product); if ($product != null) { $created_by = $product['created_by']; $category = Category::find($product['category_id']); $category = $category['category']; $user = User::find($created_by); array_add($collection, 'category', $category); array_add($collection, 'created_by_name', $user['name']); array_push($collection_list, $product); } } $collection = collect($collection_list)->sortByDesc('votes'); return response()->json(['collection-info' => $coll, 'creator' => $creator, 'products' => $collection->values()->all()]); }
public function viewUnapprovedProduct($id) { $user = Auth::user(); if ($user != null && $user->hasRole('admin')) { $coll = Collection::find($id); $collection = CollectionProduct::where('collection_id', '=', $id)->get(); // dd($collection) ; $collection_list = []; $creator = $coll->created_by; $creator = User::find($creator); foreach ($collection as $pro) { $product_id = $pro->product_id; $product = Product::find($product_id); $product = Product::add_created_by_and_category($product); if ($product != null) { $created_by = $product['created_by']; $category = Category::find($product['category_id']); $category = $category['category']; $user = User::find($created_by); array_add($collection, 'category', $category); array_add($collection, 'created_by_name', $user['name']); array_push($collection_list, $product); } } return view('admin.viewUnapprovedCollection')->with('products', $collection_list)->with('collection', $coll); } else { return view('admin.login'); } }