/** * Saves the contributors of the projects and notifies them * * @param Project $project * @param Request $request * @return string */ public function storeUsers(Project $project, Request $request) { if ($request->ajax()) { $userIds = $request->all()['ids']; foreach ($userIds as $id) { $user = User::find($id); $project->contributors()->save($user); // Send a notification to the added user $n = new Notification(); $n->sender()->associate(\Auth::user()); $n->receiver()->associate($user); $n->message = \Auth::user()->name . ' invited you to collaborate on their project'; $n->action = 'ProjectController@show|' . $project->id; $n->save(); } } return 'hello'; }