public function delete_list() { $id = Request::segment(4); Lists::where('id', $id)->delete(); $message = "Successfully deleted the list"; $type = "success"; return Redirect::to('/admin/lists')->with('type', $type)->with('message', $message); }
public function lists() { $store_id = Request::segment(2); $this->store = Store::find($store_id); if (!$this->store) { if (Request::format() == 'html') { // Not Found Page die; } else { $response_array = array('success' => 'false', 'error_code' => '404', 'error' => 'Store not Found'); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } $lists = Lists::where('list_products.store_id', $store_id)->join('list_products', 'lists.id', '=', 'list_products.list_id')->leftJoin('users', 'lists.owner_id', '=', 'users.id'); if (Input::has('category_id')) { $category_id = Input::get('category_id'); $lists = $lists->leftJoin('list_categories', 'lists.id', '=', 'list_categories.list_id')->where('list_categories.category_id', '=', $category_id); } else { if (Input::has('type')) { $type = Input::get('type'); } else { $type = 1; } if ($type == 1) { // popular $lists = $lists->orderBy('fav_count', 'desc')->take(12); } elseif ($type == 2) { $lists = $lists->where('lists.owner_id', $this->user_id); } else { $lists = $lists->leftJoin('list_favourites', 'lists.id', '=', 'list_favourites.list_id')->where('list_favourites.user_id', $this->user_id); } } $lists = $lists->select('lists.*', 'users.first_name as user_first_name', 'users.last_name as user_last_name', 'users.id as user_id', 'users.image_url as user_image_url', 'list_products.store_id')->distinct()->get(); $lists = $lists->toArray(); $response_array['lists'] = $lists; $response_array['categories'] = Category::all()->toArray(); if (Request::format() == 'html') { Session::put('store_id', $store_id); return View::make('lists')->with('data', $response_array)->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores', $this->stores); } else { $response_array['success'] = 'true'; $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } }
function saveToList($id, $contact, $linkedin_contact_id) { $item_id = null; if (Auth::check()) { $user = User::find(Auth::user()->id); if ($user->credits > 0) { $user->credits = $user->credits - 1; $user->save(); } else { $subscription = Auth::user()->subscription()->first(); $transactions = Auth::user()->subscription()->first()->transaction()->get(); $plan_id = $subscription->plan_id; $plan = Plan::find($plan_id); foreach ($transactions as $transaction) { if ($transaction->transaction_type == "charge" && $transaction->paid == 1 && $transaction->refunded == 0) { if ($transaction->credits > 0) { $transaction->credits = $transaction->credits - 1; $transaction->save(); break; } } } } $list = Lists::where('user_id', '=', $id)->first(); if (is_numeric($list->id)) { DB::table('list_item')->insert(array('lists_id' => $list->id, 'linkedin_contact_id' => $linkedin_contact_id, 'linkedin' => $contact)); $lists = DB::table('list_item')->where('lists_id', '=', $list->id)->get(); $item_id = $lists[count($lists) - 1]->id; DashboardController::cacheList($id, 0); } } return $item_id; }