File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate \Support \Facades \Schema ;
4+ use Illuminate \Database \Schema \Blueprint ;
5+ use Illuminate \Database \Migrations \Migration ;
6+
7+ class AddViewsToPosts extends Migration
8+ {
9+ const TABLE = 'blog_etc_posts ' ;
10+
11+ /**
12+ * Run the migrations.
13+ *
14+ * @return void
15+ */
16+ public function up ()
17+ {
18+ Schema::table (self ::TABLE , function (Blueprint $ table ) {
19+ $ table ->unsignedInteger ('views ' )->default (0 )->after ('user_id ' );
20+ });
21+ }
22+
23+ /**
24+ * Reverse the migrations.
25+ *
26+ * @return void
27+ */
28+ public function down ()
29+ {
30+ Schema::table (self ::TABLE , function (Blueprint $ table ) {
31+ $ table ->dropColumn ('views ' );
32+ });
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -519,4 +519,13 @@ public function post_body_output(): string
519519 {
520520 return $ this ->renderBody ();
521521 }
522+
523+ /**
524+ * Increments amount of post views.
525+ */
526+ public function gotViewed ()
527+ {
528+ $ this ->increment ('views ' );
529+ $ this ->save ();
530+ }
522531}
You can’t perform that action at this time.
0 commit comments