/**
  * Store a newly created resource in storage.
  *
  * @param  Requests\Comment\Create  $request
  * @return Response
  */
 public function store(Requests\Comment\CreateRequest $request)
 {
     $input = $request->all();
     // dd($input);
     // @todo - this is the best way to get the current logged in user?
     $input['author_id'] = \Auth::user()->id;
     // if a user is posting on their own profile then assume that they have read the comment
     if ($input['author_id'] == $input['user_id']) {
         $input['read'] = true;
     } else {
         $input['read'] = false;
     }
     \Nexus\Comment::create($input);
     return redirect("/users/" . $input['redirect_user']);
 }
Beispiel #2
0
 public function markCommentsAsRead()
 {
     Comment::where('user_id', $this->id)->update(['read' => true]);
 }
 private function migrateComments()
 {
     $this->info('Importing Comments');
     $errorCount = 0;
     if (!\Nexus\Comment::first()) {
         $count = \DB::select('select count(comment_id) as count from commenttable')[0]->count;
         $this->line("Found {$count} comments ");
         $bar = $this->output->createProgressBar($count);
         $classicComments = \DB::table('commenttable')->get();
         foreach ($classicComments as $classicComment) {
             $newComment = new \Nexus\Comment();
             $newComment->id = $classicComment->comment_id;
             $newComment->text = $classicComment->text;
             $newComment->user_id = $classicComment->user_id;
             $newComment->author_id = $classicComment->from_id;
             if ($classicComment->readstatus === 'n') {
                 $newComment->read = false;
             } else {
                 $newComment->read = true;
             }
             try {
                 $newComment->save();
                 $bar->advance();
             } catch (\Exception $e) {
                 $errorCount++;
                 \Log::error('Nexus:upgrade - Failed to add comment ' . $e);
             }
         }
         $bar->finish();
         if ($errorCount) {
             $this->error("\nEncountered {$errorCount} errors. See log for details");
         }
         $this->info("\nComments Complete\n");
         unset($classicComments);
     } else {
         $this->error('Upgrade: found existing comments - skipping Comments');
     }
 }