public function createReply($user, $replyFields) { $reply = new Reply($replyFields); $reply->author_id = $user->id; $reply->topic_id = $this->id; $reply->save(); return $reply; }
/** * Store a newly created resource in storage. * * @param $id * @param CreateAnswerRequest $request * @return Response */ public function store($id, CreateAnswerRequest $request) { $comment = Comment::findOrFail($id); $reply = new Reply(); $reply->fill($request->all()); $reply->user_id = Auth::user()->id; $reply->comment_id = $comment->id; $reply->save(); $messages = trans('messages.replies.create'); if ($request->ajax()) { return $messages; } }
public function editReply($id, EditReplyRequest $request) { $reply = Reply::findOrFail($id); $reply->update(['body' => $request->input('body'), 'editor_id' => \Auth::id(), 'editor_name' => \Auth::user()->name, 'was_edited' => 1, 'edit_reason' => $request->input('edit_reason')]); flash()->success('Udało Ci się edytować odpowiedź o ID <b>' . $id . '</b>!'); return redirect('/forum/topic/' . $request->input('take_topic_id') . ''); }
public function index(urlRequest $request) { //query if ($search = $request->query('q')) { $articles = Article::search($search)->orderBy('created_at', 'desc')->simplepaginate(18); } elseif ($search = $request->query('id')) { //查找伪id(photo) $search = \App\Article::where('photo', $search)->firstOrFail()->id; $articles = DB::table('articles')->where('id', '<=', $search)->orderBy('created_at', 'desc')->simplepaginate(18); //伪搜索结果 $search = $request->query('id'); } else { //DB::代替Article:: $articles = DB::table('articles')->orderBy('created_at', 'desc')->simplepaginate(18); } //已经点赞{!!$articles->appends(Request::except('page'))->render()!!} //$f = DB::table('votes')->whereuser_id(Auth::user()->id)->lists('votable_id'); //http://example.com/custom/url?page=N, you should pass custom/url to the setPath $articles->setPath('articles'); //sidebar $hotimgs = \App\Article::where('type', 'LIKE', "%jpg%")->orderBy('vote_count', 'desc')->take(10)->get(); //return $hotimgs; $hotreplies = \App\Reply::orderBy('vote_count', 'desc')->limit(10)->get(); return view('articles.index', compact('articles', 'search', 'hotimgs', 'hotreplies')); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $users = User::all()->sortByDesc('updated_at'); $total_users = count($users); $total_replies = \App\Reply::all()->count(); return view('users.index', compact('users', 'total_users', 'total_replies')); }
public function showTopic($id) { $topic = Topic::findOrFail($id); $replys = Reply::where('topic_id', $id)->paginate(20); if (!\Auth::guest() && \Auth::user()->isAdmin() || !\Auth::guest() && \Auth::user()->isMod()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } else { if ($topic->forumSection->forumHead['forOrg'] == 0 && $topic->forumSection->forumHead['forBiz'] == 0) { if (\Auth::guest()) { return view('forum.showTopic', compact('topic', 'replys')); } if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } else { if (!\Auth::guest() && $topic->forumSection->forumHead['forOrg'] == \Auth::user()->queryLeaderHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } elseif (!\Auth::guest() && $topic->forumSection->forumHead['forOrg'] == \Auth::user()->queryMemberHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } elseif (!\Auth::guest() && $topic->forumSection->forumHead['forBiz'] == \Auth::user()->queryBmemberHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } elseif (!\Auth::guest() && $topic->forumSection->forumHead['forBiz'] == \Auth::user()->queryBleaderHeads()) { if (!\Auth::guest() && \Auth::user()->queryExists($id)) { return view('forum.showTopic', compact('topic', 'replys')); } else { \Auth::user()->readtopic()->create(['topic_id' => $id, 'was_read' => 1, 'last_read' => Carbon::now()]); return view('forum.showTopic', compact('topic', 'replys')); } } else { flash()->error('Nie masz dostępu do tego tematu!'); return redirect('/forum'); } } } }
/** * Displays a given thread. * * @param $id int The thread to display * @return Response */ public function displayThread($id) { // We only care about the ID before the first hyphen $id = strtok($id, '-'); // Retrieve the first post of the thread $thread = Thread::where('threads.id', $id)->join('users', 'users.id', '=', 'threads.author')->select('threads.*', 'users.username')->first(); $replies = Reply::where('replies.thread', $id)->join('users', 'users.id', '=', 'replies.author')->select('replies.*', 'users.username')->paginate(20); return view('thread', compact('thread', 'replies')); }
public function setAnswer($answer) { if (!is_null($answer)) { $user = Auth::user(); $reply = Reply::firstOrNew(['user_id' => $user->id, 'question_id' => $this->id]); $reply->reply = $answer; return $reply->save(); } }
public function destroy($id) { $reply = Reply::findOrFail($id); $this->authorOrAdminPermissioinRequire($reply->user_id); $reply->delete(); $reply->topic->decrement('reply_count', 1); Flash::success(lang('Operation succeeded.')); $reply->topic->generateLastReplyUserInfo(); return redirect()->route('topics.show', $reply->topic_id); }
public function getSiteStat() { return Cache::remember(self::CACHE_KEY, self::CACHE_MINUTES, function () { $entity = new StatEntity(); $entity->topic_count = Topic::count(); $entity->reply_count = Reply::count(); $entity->user_count = User::count(); return $entity; }); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['body' => 'required']); $input = Input::all(); $input['user_id'] = Auth::user()->id; Reply::create($input); $topic = Topic::find($input['topic_id']); $topic->last_reply_user_id = Auth::id(); $topic->reply_count++; $topic->save(); return Redirect::route('topics.show', [Input::get('topic_id')]); }
public function destroy($id) { //destroy reply $reply = \App\Reply::findOrFail($id); //权限 $this->authorOrAdminPermissioinRequire($reply->user_id); $reply->article->decrement('reply_count', 1); //delete Vote $reply->votes()->delete(); $reply->delete(); return redirect('articles/' . $reply->article->photo); }
/** * Run the database seeds. * * @return void */ public function run() { $comments = \App\Comment::all(); $fake_replies = file_get_contents("http://jsonplaceholder.typicode.com/comments"); $fake_replies = json_decode($fake_replies, true); foreach ($comments as $comment) { if (mt_rand(0, 1)) { $replies = \App\Reply::where('reply_to_id', $comment->id)->get(); if (count($replies) > 0) { continue; } else { $reply = new \App\Reply(); $reply->reply_to_id = $comment->id; $one_reply = $fake_replies[mt_rand(0, count($fake_replies) - 1)]; $reply->reply_text = $one_reply['body']; $reply->save(); } } } }
/** * Run the database seeds. * * @return void */ public function run() { DB::statement('SET FOREIGN_KEY_CHECKS=0;'); print_r('truncate' . PHP_EOL); User::truncate(); Category::truncate(); Post::truncate(); Reply::truncate(); $faker = Faker::create(); User::create(['name' => 'Administrator', 'email' => '*****@*****.**', 'avatar' => 'assets/images/batman.png', 'password' => bcrypt('password'), 'remember_token' => str_random(10)]); factory(App\User::class, 50)->create(); $users = User::lists('id')->toArray(); $topics = ['lifestyle', 'nightsale', 'dota2', 'berita', 'televisi']; foreach ($topics as $t) { print_r('Creating ' . $t . PHP_EOL); $category = Category::create(['title' => $t, 'description' => $faker->text, 'slug' => str_slug($t)]); $totalPost = rand(10, 20); print_r(' Creating ' . $totalPost . ' posting' . PHP_EOL); for ($i = 0; $i < $totalPost; $i++) { $timestamp = $faker->dateTimeBetween('-1 year', 'now'); $post = Post::create(['user_id' => $faker->randomElement($users), 'category_id' => $category->id, 'title' => $faker->sentence, 'content' => $faker->paragraph(rand(1, 5)), 'created_at' => $timestamp, 'updated_at' => $timestamp]); if ($faker->boolean(60)) { $totalReply = rand(5, 20); print_r(' Creating ' . $totalReply . ' reply' . PHP_EOL); for ($j = 0; $j < $totalReply; $j++) { $timestamp = $faker->dateTimeBetween('-1 year', 'now'); $reply = Reply::create(['user_id' => $faker->randomElement($users), 'post_id' => $post->id, 'content' => $faker->paragraph(rand(1, 5)), 'created_at' => $timestamp, 'updated_at' => $timestamp]); } $post->count_reply = $totalReply; $post->save(); } } $category->count_posting = $totalPost; $category->save(); print_r('------------------' . PHP_EOL); } DB::statement('SET FOREIGN_KEY_CHECKS=1;'); }
public function create(CreatorListener $observer, $data) { $data['user_id'] = auth()->id(); $data['body'] = $this->mentionParser->parse($data['body']); $markdown = app('markdown'); $data['body_original'] = $data['body']; $data['body'] = $markdown->convertMarkdownToHtml($data['body']); $reply = Reply::create($data); if (!$reply) { return $observer->creatorFailed($reply->getErrors()); } // Add the reply user $topic = Topic::find($data['topic_id']); $topic->last_reply_user_id = auth()->id(); $topic->reply_count++; $topic->updated_at = Carbon::now(); $topic->save(); auth()->user()->increment('reply_count', 1); // TODO //App::make('Phphub\Notification\Notifier')->newReplyNotify(Auth::user(), $this->mentionParser, $topic, $reply); //Robot::notify($data['body_original'], 'Reply', $topic, Auth::user()); return $observer->creatorSucceed($reply); }
public function create(CreatorListener $observer, $data) { $data['user_id'] = Auth::id(); $data['body'] = $this->mentionParser->parse($data['body']); $markdown = new Markdown(); $data['body_original'] = $data['body']; $data['body'] = $markdown->convertMarkdownToHtml($data['body']); // Validation $this->form->validate($data); $reply = Reply::create($data); if (!$reply) { return $observer->creatorFailed($reply->getErrors()); } // Add the reply user $topic = Topic::find($data['topic_id']); $topic->last_reply_user_id = Auth::id(); $topic->reply_count++; $topic->updated_at = Carbon::now()->toDateTimeString(); $topic->save(); Auth::user()->increment('reply_count', 1); App::make('App\\good\\Notification\\Notifier')->newReplyNotify(Auth::user(), $this->mentionParser, $topic, $reply); Robot::notify($data['body_original'], 'Reply', $topic, Auth::user()); return $observer->creatorSucceed($reply); }
public function GIF(urlRequest $request) { if ($search = $request->query('q')) { $articles = \App\Article::search($search)->where('type', '.mp4')->orderBy('created_at', 'desc')->simplepaginate(18); } elseif ($search = $request->query('id')) { $search = \App\Article::where('photo', $search)->firstOrFail()->id; $articles = DB::table('articles')->where('type', '.mp4')->where('id', '<=', $search)->orderBy('created_at', 'desc')->simplepaginate(18); $search = $request->query('id'); } else { $articles = DB::table('articles')->where('type', '.mp4')->orderBy('created_at', 'desc')->simplepaginate(18); } $articles->setPath('GIF'); $hotimgs = \App\Article::where('type', 'LIKE', "%jpg%")->orderBy('vote_count', 'desc')->take(10)->get(); $hotreplies = \App\Reply::orderBy('vote_count', 'desc')->limit(10)->get(); return view('articles.index', compact('articles', 'search', 'hotimgs', 'hotreplies')); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $Reply = Reply::find($id); if ($Reply->type_id == Reply::TYPE_CONTENT) { $Content = $Reply->entity; $route = route($Content->getAppointRoute('show'), $Content->id) . '#section-content-replys'; } else { if ($Reply->type_id == Reply::TYPE_COMMENT) { $Comment = $Reply->entity; $Content = $Comment->entity; $route = route($Content->getAppointRoute('show'), $Content->id) . '#section-comment-replys-' . $Comment->id; } } return redirect()->to($route); }
$images = get_all_images_from_property_id($property->id); /* Raw SQL query to find the average rating on a property */ $num_stars = DB::select("SELECT AVG(comments.rating) AS 'avg' FROM comments JOIN properties ON properties.id = comments.property_id WHERE comments.property_id = " . $property->id); if (count($num_stars > 0)) { $num_stars = $num_stars[0]->avg; $num_stars = floor($num_stars * 2) / 2; } else { $num_stars = null; } $property->num_stars = $num_stars; /* Get all the comments on this property */ $comments = Comment::where('property_id', $property->id)->get(); foreach ($comments as $comment) { $comment->author_pic = get_thumbnail_from_user_id($comment->user_id); $comment->author = User::find($comment->user_id); $reply = \App\Reply::where('reply_to_id', $comment->id)->get(); $comment->reply = $reply; } /* Get all the comments for this user */ $all_owner_properties = Property::where('owner_id', $owner->id)->get(); $all_owner_comments = array(); foreach ($all_owner_properties as $owner_property) { $property_comments = Comment::where('property_id', $owner_property->id)->get(); foreach ($property_comments as $owner_property_comment) { array_push($all_owner_comments, $owner_property_comment); } } $owner->number_of_reviews = count($all_owner_comments); /* Get this district */ $district = District::find($property->district_id); /* Get the POIs for this district */
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $reply = Reply::find($id); if ($reply->user_id == Auth::id()) { if ($reply->delete()) { DB::table('reviews')->where('id', $reply->review_id)->decrement('replies'); } } return redirect()->back(); }
public function replies($id) { $user = User::findOrFail($id); $replies = Reply::whose($user->id)->recent()->paginate(30); return view('users.replies', compact('user', 'replies')); }
public function replyUpVote(Reply $reply) { if (auth()->id() == $reply->user_id) { return Flash::warning(lang('Can not vote your feedback')); } if ($reply->votes()->ByWhom(auth()->id())->WithType('upvote')->count()) { // click twice for remove upvote $reply->votes()->ByWhom(auth()->id())->WithType('upvote')->delete(); $reply->decrement('vote_count', 1); } elseif ($reply->votes()->ByWhom(auth()->id())->WithType('downvote')->count()) { // user already clicked downvote once $reply->votes()->ByWhom(auth()->id())->WithType('downvote')->delete(); $reply->votes()->create(['user_id' => auth()->id(), 'is' => 'upvote']); $reply->increment('vote_count', 2); } else { // first time click $reply->votes()->create(['user_id' => auth()->id(), 'is' => 'upvote']); $reply->increment('vote_count', 1); Notification::notify('reply_upvote', auth()->user(), $reply->user, $reply->topic, $reply); } }
public function savereply(ReplyRequest $requests) { $id = $requests->input('message_id'); Reply::create($requests->all()); return redirect('messages/read/' . $id); }
public function replyUpVote(Reply $reply) { if ($reply->votes()->ByWhom(Auth::id())->WithType('upvote')->count()) { // click twice for remove upvote $reply->votes()->ByWhom(Auth::id())->WithType('upvote')->delete(); $reply->decrement('vote_count', 1); } elseif ($reply->votes()->ByWhom(Auth::id())->WithType('downvote')->count()) { // user already clicked downvote once $reply->votes()->ByWhom(Auth::id())->WithType('downvote')->delete(); $reply->votes()->create(['user_id' => Auth::id(), 'is' => 'upvote']); $reply->increment('vote_count', 2); } else { // first time click $reply->votes()->create(['user_id' => Auth::id(), 'is' => 'upvote']); $reply->increment('vote_count', 1); Notification::notify('reply_upvote', Auth::user(), $reply->user, $reply->topic, $reply); } }
public function createNewsReply(array $data) { $reply = Reply::Create(['keyword_rule_id' => $data['keyword_rule_id'], 'reply_type' => $data['reply_type']]); ReplyNews::firstOrCreate(['reply_id' => $reply->id, 'content' => $data['msg_content']]); return Reply::with('news')->find($reply->id()); }