示例#1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Project $project, User $user, Request $request)
 {
     $this->validate($request, ['type' => 'in:owner,developer,client', 'user_id' => 'exists:users_projects']);
     $data = ['type' => $request->get('type')];
     $project->users()->updateExistingPivot($user->id, $data);
     return response()->json(['success' => true, 'message' => 'Project Member updated.']);
 }
 /**
  * User stars/un-stars a project (POST)
  *
  * @param Project $project
  * @return array JSON response
  */
 public function postStar(Project $project)
 {
     $response = array();
     $response['project'] = $project->toArray();
     if (!in_array(Auth::user()->id, $project->users()->lists('id')->toArray())) {
         Auth::user()->projects()->attach($project->id);
         $response['message'] = "成功收藏&nbsp;<span>" . $project->title . "</span>";
     } else {
         Auth::user()->projects()->detach($project->id);
         $response['message'] = "已取消收藏&nbsp;<span>" . $project->title . "</span>";
     }
     return $response;
 }
 /**
  * API to detach a user to a project
  */
 public function apiRemoveUserFromProject(Project $project, User $user)
 {
     event(new UserRemovedFromProject($user, $project));
     return $project->users()->detach($user);
 }