예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['content' => 'required', 'review_id' => 'required|exists:reviews,id', 'user_id' => 'required|exists:users,id']);
     if ($reply = Reply::create(Input::all())) {
         DB::table('reviews')->where('id', $reply->review_id)->increment('replies');
         return redirect()->back();
     } else {
         return redirect()->back()->withInput()->withErrors('添加失败');
     }
 }
예제 #2
0
 /**
  * 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')]);
 }
예제 #3
0
 public function store(ReplyRequest $request)
 {
     //save reply
     $request['user_id'] = Auth::id();
     $request['body'] = $this->mentionParser->parse($request['body']);
     //return  $request['body'];
     $reply = Reply::create($request->all());
     //reply count+1
     $article = Article::find($request['article_id']);
     $article->reply_count++;
     $article->updated_at = Carbon::now();
     $article->save();
     //通知  after user
     App('App\\good\\Notification\\Notifier')->newReplyNotify(Auth::user(), $this->mentionParser, $article, $reply);
     return back();
 }
예제 #4
0
 /**
  * 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;');
 }
예제 #5
0
 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);
 }
예제 #7
0
 public function savereply(ReplyRequest $requests)
 {
     $id = $requests->input('message_id');
     Reply::create($requests->all());
     return redirect('messages/read/' . $id);
 }