Skip to content

Commit aac3ce8

Browse files
committed
feat: version change notification
1 parent 8dea5c1 commit aac3ce8

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

app/Models/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
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
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
};

0 commit comments

Comments
 (0)