File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed
Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Http \Middleware ;
4+
5+ use Closure ;
6+ use Illuminate \Http \Request ;
7+ use Illuminate \Support \Facades \Session ;
8+ use Symfony \Component \HttpFoundation \Response ;
9+
10+ class VersionChangeNotification
11+ {
12+ /**
13+ * Handle an incoming request.
14+ *
15+ * @param Closure(Request): (Response) $next
16+ */
17+ public function handle (Request $ request , Closure $ next ): Response
18+ {
19+ if (($ user = \Auth::user ()) !== null ) {
20+ $ lastVersion = $ user ->version ;
21+ if ($ lastVersion !== config ('stufis.version ' )) {
22+ Session::put ('message.text ' , __ ('general.version_notification.text ' ));
23+ Session::put ('message.type ' , 'update ' );
24+ $ user ->update (['version ' => config ('stufis.version ' )]);
25+ }
26+ }
27+
28+ return $ next ($ request );
29+ }
30+ }
Original file line number Diff line number Diff line change 3030 * @property string $picture_url
3131 * @property string $iban
3232 * @property string $address
33+ * @property string $version the last seen stufis version number
3334 * @property string|null $remember_token
3435 * @property Carbon|null $created_at
3536 * @property Carbon|null $updated_at
@@ -90,6 +91,7 @@ class User extends Authenticatable
9091 'picture_url ' ,
9192 'iban ' ,
9293 'address ' ,
94+ 'version ' ,
9395 ];
9496
9597 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use App \Models \User ;
4+ use Illuminate \Database \Migrations \Migration ;
5+ use Illuminate \Database \Schema \Blueprint ;
6+ use Illuminate \Support \Facades \Schema ;
7+
8+ return new class extends Migration
9+ {
10+ /**
11+ * Run the migrations.
12+ */
13+ public function up (): void
14+ {
15+ Schema::table ('user ' , function (Blueprint $ table ) {
16+ $ table ->string ('version ' )->after ('address ' );
17+ });
18+ // give all existing users a value, so they get the update message
19+ User::update (['version ' => '4.2.6 ' ]);
20+ }
21+
22+ /**
23+ * Reverse the migrations.
24+ */
25+ public function down (): void
26+ {
27+ Schema::table ('user ' , function (Blueprint $ table ) {
28+ $ table ->dropColumn ('version ' );
29+ });
30+ }
31+ };
You can’t perform that action at this time.
0 commit comments