diff --git a/app/Comment.php b/app/Comment.php new file mode 100644 index 000000000..fd050a720 --- /dev/null +++ b/app/Comment.php @@ -0,0 +1,18 @@ +belongsTo(Profile::class); + } + + public function status() + { + return $this->belongsTo(Status::class); + } +} diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php new file mode 100644 index 000000000..2150bf4ef --- /dev/null +++ b/app/Http/Controllers/CommentController.php @@ -0,0 +1,42 @@ +validate($request, [ + 'item' => 'required|alpha_num', + 'comment' => 'required|string|max:500' + ]); + + try { + $statusId = Hashids::decode($request->item)[0]; + } catch (Exception $e) { + abort(500); + } + + $user = Auth::user(); + $profile = $user->profile; + $status = Status::findOrFail($statusId); + + $comment = new Comment; + $comment->profile_id = $profile->id; + $comment->user_id = $user->id; + $comment->status_id = $status->id; + $comment->comment = e($request->comment); + $comment->rendered = e($request->comment); + $comment->is_remote = false; + $comment->entities = null; + $comment->save(); + + return redirect($status->url()); + } +} diff --git a/database/migrations/2018_04_18_044421_create_comments_table.php b/database/migrations/2018_04_18_044421_create_comments_table.php new file mode 100644 index 000000000..378137787 --- /dev/null +++ b/database/migrations/2018_04_18_044421_create_comments_table.php @@ -0,0 +1,39 @@ +bigIncrements('id'); + $table->bigInteger('profile_id')->unsigned(); + $table->bigInteger('user_id')->unsigned()->nullable(); + $table->bigInteger('status_id')->unsigned(); + $table->text('comment')->nullable(); + $table->text('rendered')->nullable(); + $table->json('entities')->nullable(); + $table->boolean('is_remote')->default(false); + $table->timestamp('rendered_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('comments'); + } +}