public function index($userId = null) { $auth = auth(); if (!$userId) { $userId = $auth->id(); $isAuthUser = true; } else { $isAuthUser = $userId == $auth->id(); } if ($isAuthUser) { $user = $auth->user(); } else { $user = User::findOrFail($userId); } $count['create'] = Project::where('user_id', $userId)->count(); $count['join'] = Project::join('project_members', function ($join) use($userId) { $join->on('projects.id', '=', 'project_members.project_id')->where('project_members.user_id', '=', $userId); })->where('projects.user_id', '<>', $userId)->count(); $count['comment'] = 0; $count['collect'] = ProjectFavorite::where('user_id', $userId)->count(); $showList = 'create'; foreach ($count as $key => $value) { if ($value > 0) { $showList = $key; break; } } return view('user.home.index', ['userData' => $user, 'isAuthUser' => $isAuthUser, 'projectCount' => $count, 'showList' => $showList]); }
protected function getUserProjectCount($userId) { $count = []; $count['create'] = Project::where('user_id', $userId)->count(); $count['join'] = Project::join('project_members', function ($join) use($userId) { $join->on('projects.id', '=', 'project_members.project_id')->where('project_members.user_id', '=', $userId); })->where('projects.user_id', '<>', $userId)->count(); $count['comment'] = 0; $count['collect'] = 0; return $count; }
protected function getCollect($startId, $userId) { $this->startIdKey = 'favorite_id'; $startId = intval($startId); $builder = Project::join('project_favorites', function ($join) use($startId, $userId) { $join->on('projects.id', '=', 'project_favorites.project_id')->where('project_favorites.user_id', '=', $userId); if ($startId > 0) { $join->where('id', '<', $startId); } })->where('projects.user_id', '<>', $userId); return $builder->orderBy('project_favorites.id', 'desc')->take($this->listTake)->get(['projects.*', 'project_favorites.id as favorite_id']); }
public function project(Request $request, $projectId) { $project = Project::with(['photos', 'youtubes'])->find($projectId); return view('frontends.project')->with('project', $project); }
public function doReject(Request $request, $id) { /* @var Project $project */ $project = Project::with(['status'])->find($id); $previousStatus = ProjectStatus::where("key", '=', "draft")->first(); $approveForm = $request->get('acceptForm'); $approveComment = new ProjectApproveComment(); $approveComment->project_id = $id; $approveComment->user_id = Auth::user()->id; $approveComment->is_accept = false; $approveComment->comment = $approveForm['comment']; $approveComment->from_status_id = $project->status->id; $approveComment->to_status_id = $previousStatus->id; $approveComment->save(); $project->status()->associate($previousStatus)->save(); return $project; }
public function doSaveMap(Request $request, $projectId) { $project_form = $request->get('project'); $project = Project::find($projectId); if (!$project) { return redirect('backend/admin/project'); } $project->geojson = $project_form['geojson']; $project->save(); return redirect("/backend/admin/project/{$projectId}/edit/sixth"); }
protected function getProject() { if (!isset($this->projectData)) { $this->projectData = Project::with(['user', 'members' => function ($query) { $query->orderBy('id', 'asc'); }, 'members.user'])->find($this->projectId); } return $this->projectData; }
Route::get('/post/{id}', "FrontendController@getPost"); }); Route::get('/amphur/{id}/{name}', function ($id, $name) { $amphur = \App\Models\Thailand\Amphur::find($id); $query = Project::query(); $query->where('amphur_id', '=', $id); $projects = $query->get(); return view('frontends.amphur')->with('projects', $projects)->with('amphur', $amphur); }); Route::group(['prefix' => 'project', 'middleware' => ['web']], function () { //project Route::get('/', function (\Symfony\Component\HttpFoundation\Request $request) { $faculty_id = $request->get('faculty_id'); $keyword = $request->get('keyword'); $year = $request->get('year'); $query = Project::query(); if ($faculty_id) { $query = $query->where('faculty_id', '=', $faculty_id); } if ($keyword) { $query = $query->where('name_th', 'LIKE', "%{$keyword}%"); $query = $query->orWhere('name_en', 'LIKE', "%{$keyword}%"); } if ($year) { $query = $query->where('year', '=', $year); } $query->whereHas('status', function ($q) { $q->where('key', '=', 'published'); }); $projects = $query->get(); return view('frontends.search')->with('projects', $projects);
public function previewProject(Request $request, $id, $role) { $project = Project::find($id); return view('backends.project.preview')->with('project', $project)->with('previewRole', $role); }