/** * Created By Dara on 8/2/2016 * add reply to comment */ public function session(Session $session, $comment_id, Request $request) { $user = $this->user; $this->validate($request, ['content' => 'required']); if ($comment_id) { //check if the comment has been set or not (reply) level 2 comment $comment = Comment::findOrFail($comment_id); $parent_id = $comment->id; $msg = trans('users.answerSent'); $nested = true; } else { //level 1 comment $parent_id = 0; $msg = trans('users.commentSent'); $nested = false; } //add comment to db $newComment = $session->comments()->create(['user_id' => $user->id, 'content' => $request->input('content'), 'parent_id' => $parent_id]); $numComment = $session->comments()->count(); $session->update(['num_comment' => $numComment]); $obj = $session; $model = 'session'; return ['hasCallback' => 1, 'callback' => 'session_comment', 'hasMsg' => 1, 'msgType' => '', 'msg' => $msg, 'returns' => ['newComment' => view('comment.comment', compact('newComment', 'session', 'user', 'obj', 'model'))->render(), 'nested' => $nested, 'numComment' => $numComment]]; }
/** * Created By Dara on 22/2/2016 * update session */ public function update(Course $course, Session $session, Request $request) { $user = $this->user; $this->validate($request, ['title' => 'required', 'file' => 'required|max:50', 'description' => 'required', 'active' => 'required|in:0,1', 'level' => 'required|in:1,2,3', 'tags.*' => 'min:2|max:30']); $input = $request->all(); /*check if the given link for video valid or not*/ $fileName = $input['file']; //text-input if (Storage::disk('local')->exists($fileName)) { //ok $path = storage_path('app/' . $fileName); $capacity = File::size($path); } else { //not exists $fileName = null; $capacity = null; } /*add the session in db*/ $session->update(['title' => $input['title'], 'description' => $input['description'], 'active' => $input['active'], 'file' => $fileName, 'level' => $input['level'], 'capacity' => $capacity]); $this->session_id = $session->id; /*add tags to the sessions*/ $selected = $this->registerTags($request); $session->tags()->sync($selected); /*check for attachments*/ if ($request->hasFile('attachment')) { $attachments = $input['attachment']; /*validate attachments*/ /*-------------------------------------------------*/ foreach ($attachments as $key => $attachment) { $attachmentName = $user->id . '_' . $course->id . '_' . str_random(20) . '.' . $attachment->getClientOriginalExtension(); $attachmentRealName = $attachment->getClientOriginalName(); Storage::disk('local')->put($attachmentName, File::get($attachment)); $user->attachments()->create(['parentable_id' => $this->session_id, 'parentable_type' => 'App\\Session', 'real_name' => $attachmentRealName, 'size' => round($attachment->getClientSize() / 1024, 2), 'file' => $attachmentName]); } } Flash::success(trans('users.sessionUpdated')); return redirect()->back(); }