File tree Expand file tree Collapse file tree 5 files changed +125
-0
lines changed Expand file tree Collapse file tree 5 files changed +125
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Models ;
4
+
5
+ use Illuminate \Database \Eloquent \Factories \HasFactory ;
6
+ use Illuminate \Database \Eloquent \Model ;
7
+
8
+ class Like extends Model
9
+ {
10
+ use HasFactory;
11
+
12
+ protected $ fillable = [
13
+ 'user_id ' , 'post_id ' ,
14
+ ];
15
+
16
+ public function post ()
17
+ {
18
+ return $ this ->belongsTo (Post::class);
19
+ }
20
+
21
+ public function user ()
22
+ {
23
+ return $ this ->belongsTo (User::class);
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Models ;
4
+
5
+ use Illuminate \Database \Eloquent \Factories \HasFactory ;
6
+ use Illuminate \Database \Eloquent \Model ;
7
+
8
+ class Share extends Model
9
+ {
10
+ use HasFactory;
11
+
12
+ protected $ fillable = [
13
+ 'user_id ' , 'post_id ' ,
14
+ ];
15
+
16
+ public function post ()
17
+ {
18
+ return $ this ->belongsTo (Post::class);
19
+ }
20
+
21
+ public function user ()
22
+ {
23
+ return $ this ->belongsTo (User::class);
24
+ }
25
+ }
Original file line number Diff line number Diff line change @@ -16,7 +16,10 @@ public function up()
16
16
$ table ->text ('content ' )->nullable ();
17
17
$ table ->string ('image_path ' )->nullable ();
18
18
$ table ->unsignedInteger ('comments_count ' )->default (0 );
19
+ $ table ->unsignedInteger ('likes_count ' )->default (0 );
20
+ $ table ->unsignedInteger ('shares_count ' )->default (0 );
19
21
$ table ->unsignedBigInteger ('user_id ' );
22
+ $ table ->unsignedBigInteger ('shareduser_id ' )->default (0 );
20
23
$ table ->foreign ('user_id ' )->references ('id ' )->on ('users ' )->onDelete ('cascade ' );
21
24
$ table ->softDeletes ();
22
25
$ table ->timestamps ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Illuminate \Database \Migrations \Migration ;
4
+ use Illuminate \Database \Schema \Blueprint ;
5
+ use Illuminate \Support \Facades \Schema ;
6
+
7
+ return new class extends Migration
8
+ {
9
+ /**
10
+ * Run the migrations.
11
+ *
12
+ * @return void
13
+ */
14
+ public function up ()
15
+ {
16
+ Schema::create ('likes ' , function (Blueprint $ table ) {
17
+ $ table ->id ();
18
+ $ table ->unsignedBigInteger ('user_id ' );
19
+ $ table ->unsignedBigInteger ('post_id ' );
20
+ $ table ->timestamps ();
21
+
22
+ $ table ->foreign ('user_id ' )->references ('id ' )->on ('users ' )->onDelete ('cascade ' );
23
+ $ table ->foreign ('post_id ' )->references ('id ' )->on ('posts ' )->onDelete ('cascade ' );
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Reverse the migrations.
29
+ *
30
+ * @return void
31
+ */
32
+ public function down ()
33
+ {
34
+ Schema::dropIfExists ('likes ' );
35
+ }
36
+ };
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Illuminate \Database \Migrations \Migration ;
4
+ use Illuminate \Database \Schema \Blueprint ;
5
+ use Illuminate \Support \Facades \Schema ;
6
+
7
+ return new class extends Migration
8
+ {
9
+ /**
10
+ * Run the migrations.
11
+ *
12
+ * @return void
13
+ */
14
+ public function up ()
15
+ {
16
+ Schema::create ('shares ' , function (Blueprint $ table ) {
17
+ $ table ->id ();
18
+ $ table ->unsignedBigInteger ('user_id ' );
19
+ $ table ->unsignedBigInteger ('post_id ' );
20
+ $ table ->timestamps ();
21
+
22
+ $ table ->foreign ('user_id ' )->references ('id ' )->on ('users ' )->onDelete ('cascade ' );
23
+ $ table ->foreign ('post_id ' )->references ('id ' )->on ('posts ' )->onDelete ('cascade ' );
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Reverse the migrations.
29
+ *
30
+ * @return void
31
+ */
32
+ public function down ()
33
+ {
34
+ Schema::dropIfExists ('shares ' );
35
+ }
36
+ };
You can’t perform that action at this time.
0 commit comments