/** * Returns the id of a project given by name. * Throws an exception if no project was found. * * @param string $name The name of the project * @return mixed * @throws RuntimeException */ protected function getProjectIdByName($name) { $collection = Project::where('name', $name)->get(); if ($collection->count() === 0) { throw new RuntimeException('No project found for name: ' . $name); } return $collection->shift()->id; }
public function showHome() { //gets latest post $news = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 1)->orderBy('updated_at', 'desc')->first(); $job = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 2)->orderBy('updated_at', 'desc')->first(); $product = Product::where('is_active', 1)->orderby('updated_at', 'desc')->first(); $project = Project::where('is_public', 1)->where('is_active', 1)->orderBy('updated_at', 'desc')->first(); $newsContent = htmlspecialchars_decode($news->content, ENT_NOQUOTES); $news->content = $newsContent; //dd($news); return view('pages.home', ['news' => $news, 'job' => $job, 'product' => $product, 'project' => $project]); }
public function show($id) { if (!preg_match("/^[1-9]\\d*\$/", $id)) { return Redirect::to('/'); } $type = Category::find($id); if (!$type) { return Redirect::to(route('admin.projects.index')); } $projects = Project::where('category_id', $id)->sortByDesc('id')->paginate(20); return Theme::view('admin.projects.show', compact('projects', 'type')); }
public function getType($id) { if (!preg_match("/^[1-9]\\d*\$/", $id)) { return Redirect::to('/'); } $type = Category::find($id); if (empty($type)) { return Redirect::to('/'); } $keywords = $type->keywords; $description = $type->description; $projects = Project::where('category_id', $id)->sortByDesc('id')->paginate(20); return Theme::view('project.index', compact(['projects', 'type', 'keywords', 'description'])); }
public static function project_data($num, $order = null, $where = null, $type = 0, $offset = 0) { $num = intval($num); $offset = intval($offset); $key = 'project_' . $num . '_' . $order . '_' . $where . '_' . $type . '_' . $offset; if (Cache::store('project')->has($key)) { $date = Cache::store('project')->get($key); return $date; } else { switch ($order) { case byId: $order_str = 'id'; break; case bySort: $order_str = 'sort'; break; case byViews: $order_str = 'views'; break; case byCost: $order_str = 'cost'; break; default: $order_str = 'id'; break; } $type = intval($type); switch ($where) { case findAll: $date = Project::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findRecommend: $date = Project::where('is_recommend', '>', 0)->sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findCategory: $date = Project::where('category_id', $type)->orderBy($order_str, 'desc')->take($num)->Offset($offset)->get(); break; default: $date = Project::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; } $expiresAt = Carbon::now()->addMinutes(60); //设置缓存时间 Cache::store('project')->put($key, $date, $expiresAt); return $date; } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { try { $this->validate($request, ['project_name' => 'required|max:255|min:3', 'project_desc' => 'required|min:1|max:500']); $ispublic = $request->input('is_public') ? true : false; $isactive = $request->input('is_active') ? true : false; $projectobj = new Project(); $projectobj->where('id', $id)->update(['project_name' => $request->input('project_name'), 'project_desc' => $request->input('project_desc'), 'is_public' => $ispublic, 'is_active' => $isactive]); if ($request->input('fileId') != '' && $request->input('fileId') != null) { $fileIdArr = explode(' ', $request->input('fileId')); foreach ($fileIdArr as $fileId) { Files::where('id', $fileId)->update(['attachment_id' => $request->input('id')]); } } //update attachment images if ($request->has('img')) { foreach ($request->input('img') as $img) { //unserialize image value $imgVal = unserialize($img); if ($imgVal[1]) { $fileObj = new Files(); $fileObj->where('id', $imgVal[0])->update(['attachment_id' => $id]); } else { $fileObj = new Files(); $fileObj->where('id', $imgVal[0])->update(['is_active' => false]); } } } return Redirect::to("/back/project/edit/{$id}")->with('message', $request->input('project_name') . ' was successfully updated'); } catch (Exception $e) { return Redirect::to("/back/project/edit/{$id}")->with('message', 'Oops! Something went wrong. Please try again later'); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $users = \App\User::get(); $row = Project::where('id', $id)->first(); if ($row) { return view('project.create', ['row' => $row, 'users' => $users]); } else { return redirect('/project'); } }