Skip to content

Commit 5f82493

Browse files
author
nejc
committed
Initial version platform manager package implementation
1 parent 49deb1c commit 5f82493

26 files changed

+2013
-0
lines changed

INSTALLATION.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Installation Guide
2+
3+
## Step 1: Add the Package to Your Project
4+
5+
Add the package to your `composer.json`:
6+
7+
```json
8+
{
9+
"require": {
10+
"laravelplus/version-platform-manager": "dev-master"
11+
},
12+
"repositories": [
13+
{
14+
"type": "path",
15+
"url": "./packages/laravelplus/version-platform-manager"
16+
}
17+
]
18+
}
19+
```
20+
21+
## Step 2: Install Dependencies
22+
23+
```bash
24+
composer install
25+
```
26+
27+
## Step 3: Publish the Package
28+
29+
```bash
30+
php artisan vendor:publish --provider="LaravelPlus\VersionPlatformManager\Providers\VersionPlatformManagerServiceProvider"
31+
```
32+
33+
## Step 4: Run Migrations
34+
35+
```bash
36+
php artisan migrate
37+
```
38+
39+
## Step 5: Add the Trait to Your User Model
40+
41+
Add the `HasVersion` trait to your `User` model:
42+
43+
```php
44+
<?php
45+
46+
namespace App\Models;
47+
48+
use LaravelPlus\VersionPlatformManager\Traits\HasVersion;
49+
50+
class User extends Authenticatable
51+
{
52+
use HasVersion;
53+
54+
// ... rest of your model
55+
}
56+
```
57+
58+
## Step 6: Replace the Existing Component
59+
60+
Replace your existing `what-is-new.blade.php` component with the package component:
61+
62+
```php
63+
// In your home.blade.php or any view
64+
<x-version-platform-manager::whats-new></x-version-platform-manager::whats-new>
65+
```
66+
67+
## Step 7: Create Initial Data (Optional)
68+
69+
Run the seeder to create sample data:
70+
71+
```bash
72+
php artisan db:seed --class="LaravelPlus\VersionPlatformManager\Database\Seeders\VersionPlatformManagerSeeder"
73+
```
74+
75+
## Step 8: Test the Package
76+
77+
Create a platform version:
78+
79+
```bash
80+
php artisan version-platform:create-version "1.0.0" "Initial Release" --description="Welcome to our platform!"
81+
```
82+
83+
Create what's new content:
84+
85+
```bash
86+
php artisan version-platform:create-whats-new "1.0.0" "New Feature" "This is a new feature description" --type=feature
87+
```
88+
89+
## Usage Examples
90+
91+
### In Your Views
92+
93+
```php
94+
// Show what's new modal (automatically checks user version)
95+
<x-version-platform-manager::whats-new></x-version-platform-manager::whats-new>
96+
```
97+
98+
### In Your Controllers
99+
100+
```php
101+
use LaravelPlus\VersionPlatformManager\Services\VersionService;
102+
103+
class HomeController extends Controller
104+
{
105+
public function index(VersionService $versionService)
106+
{
107+
$user = auth()->user();
108+
109+
// Check if user needs updates
110+
if ($versionService->userNeedsUpdate($user)) {
111+
$whatsNew = $versionService->getWhatsNewForUser($user);
112+
// Handle updates...
113+
}
114+
115+
return view('home');
116+
}
117+
}
118+
```
119+
120+
### Using the User Model
121+
122+
```php
123+
$user = auth()->user();
124+
125+
// Check if user needs updates
126+
if ($user->needsVersionUpdate()) {
127+
$whatsNew = $user->getWhatsNew();
128+
// Handle updates...
129+
}
130+
131+
// Update user version
132+
$user->updateVersion('1.1.0');
133+
```
134+
135+
## Configuration
136+
137+
The package configuration is published to `config/version-platform-manager.php`. You can customize:
138+
139+
- Default user version
140+
- Version comparison method
141+
- Modal settings
142+
- Admin panel settings
143+
- Feature types
144+
145+
## Admin Panel
146+
147+
Access the admin panel at `/admin/versions` to manage:
148+
149+
- Platform versions
150+
- What's new content
151+
- User version statistics
152+
153+
## Console Commands
154+
155+
- `php artisan version-platform:create-version` - Create a new platform version
156+
- `php artisan version-platform:create-whats-new` - Create new what's new content
157+
158+
## Troubleshooting
159+
160+
### Common Issues
161+
162+
1. **Component not showing**: Make sure the user is authenticated and has a version older than the latest platform version.
163+
164+
2. **Migration errors**: Ensure all migrations are run and the database tables exist.
165+
166+
3. **Trait not working**: Make sure the `HasVersion` trait is added to your `User` model.
167+
168+
### Support
169+
170+
For issues and questions, please check the package documentation or create an issue in the repository.

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "laravelplus/version-platform-manager",
3+
"description": "A Laravel package for managing platform versions and showing what's new to users",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "LaravelPlus Team",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.1",
14+
"laravel/framework": "^10.0|^11.0|^12.0"
15+
},
16+
"require-dev": {
17+
"orchestra/testbench": "^8.0|^9.0|^10.0",
18+
"phpunit/phpunit": "^10.0",
19+
"pestphp/pest": "^2.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"LaravelPlus\\VersionPlatformManager\\": "src/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"LaravelPlus\\VersionPlatformManager\\Tests\\": "tests/"
29+
}
30+
},
31+
"extra": {
32+
"laravel": {
33+
"providers": [
34+
"LaravelPlus\\VersionPlatformManager\\Providers\\VersionPlatformManagerServiceProvider"
35+
]
36+
}
37+
},
38+
"config": {
39+
"sort-packages": true
40+
},
41+
"minimum-stability": "stable",
42+
"prefer-stable": true
43+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Default User Version
7+
|--------------------------------------------------------------------------
8+
|
9+
| The default version assigned to new users when they register.
10+
|
11+
*/
12+
'default_user_version' => env('DEFAULT_USER_VERSION', '1.0.0'),
13+
14+
/*
15+
|--------------------------------------------------------------------------
16+
| Version Comparison
17+
|--------------------------------------------------------------------------
18+
|
19+
| How to compare versions. Options: 'semantic', 'numeric', 'string'
20+
|
21+
*/
22+
'version_comparison' => env('VERSION_COMPARISON', 'semantic'),
23+
24+
/*
25+
|--------------------------------------------------------------------------
26+
| Modal Settings
27+
|--------------------------------------------------------------------------
28+
|
29+
| Settings for the what's new modal display.
30+
|
31+
*/
32+
'modal' => [
33+
'auto_show' => env('VERSION_MODAL_AUTO_SHOW', true),
34+
'dismissible' => env('VERSION_MODAL_DISMISSIBLE', true),
35+
'show_once_per_session' => env('VERSION_MODAL_SHOW_ONCE_PER_SESSION', true),
36+
'delay' => env('VERSION_MODAL_DELAY', 1000), // milliseconds
37+
],
38+
39+
/*
40+
|--------------------------------------------------------------------------
41+
| Admin Panel
42+
|--------------------------------------------------------------------------
43+
|
44+
| Settings for the admin panel.
45+
|
46+
*/
47+
'admin' => [
48+
'enabled' => env('VERSION_ADMIN_ENABLED', true),
49+
'route_prefix' => env('VERSION_ADMIN_ROUTE_PREFIX', 'admin/versions'),
50+
'middleware' => ['web', 'auth'],
51+
],
52+
53+
/*
54+
|--------------------------------------------------------------------------
55+
| Database Tables
56+
|--------------------------------------------------------------------------
57+
|
58+
| Table names for the package.
59+
|
60+
*/
61+
'tables' => [
62+
'platform_versions' => 'platform_versions',
63+
'whats_new' => 'whats_new',
64+
'user_versions' => 'user_versions',
65+
],
66+
67+
/*
68+
|--------------------------------------------------------------------------
69+
| Features
70+
|--------------------------------------------------------------------------
71+
|
72+
| Feature types for what's new content.
73+
|
74+
*/
75+
'feature_types' => [
76+
'feature' => 'New Feature',
77+
'improvement' => 'Improvement',
78+
'bugfix' => 'Bug Fix',
79+
'security' => 'Security Update',
80+
'deprecation' => 'Deprecation',
81+
],
82+
83+
/*
84+
|--------------------------------------------------------------------------
85+
| Notifications
86+
|--------------------------------------------------------------------------
87+
|
88+
| Notification settings for version updates.
89+
|
90+
*/
91+
'notifications' => [
92+
'enabled' => env('VERSION_NOTIFICATIONS_ENABLED', true),
93+
'channels' => ['mail', 'database'],
94+
],
95+
];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
public function up(): void
13+
{
14+
Schema::create('platform_versions', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('version')->unique();
17+
$table->string('title');
18+
$table->text('description')->nullable();
19+
$table->boolean('is_active')->default(true);
20+
$table->timestamp('released_at')->nullable();
21+
$table->json('metadata')->nullable();
22+
$table->timestamps();
23+
$table->softDeletes();
24+
25+
// Indexes for better performance
26+
$table->index(['version']);
27+
$table->index(['is_active']);
28+
$table->index(['released_at']);
29+
$table->index(['created_at']);
30+
});
31+
}
32+
33+
/**
34+
* Reverse the migrations.
35+
*/
36+
public function down(): void
37+
{
38+
Schema::dropIfExists('platform_versions');
39+
}
40+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
public function up(): void
13+
{
14+
Schema::create('whats_new', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignId('platform_version_id')->constrained()->onDelete('cascade');
17+
$table->string('title');
18+
$table->text('content');
19+
$table->enum('type', ['feature', 'improvement', 'bugfix', 'security', 'deprecation'])->default('feature');
20+
$table->boolean('is_active')->default(true);
21+
$table->integer('sort_order')->default(0);
22+
$table->json('metadata')->nullable();
23+
$table->timestamps();
24+
$table->softDeletes();
25+
26+
// Indexes for better performance
27+
$table->index(['platform_version_id']);
28+
$table->index(['type']);
29+
$table->index(['is_active']);
30+
$table->index(['sort_order']);
31+
$table->index(['created_at']);
32+
});
33+
}
34+
35+
/**
36+
* Reverse the migrations.
37+
*/
38+
public function down(): void
39+
{
40+
Schema::dropIfExists('whats_new');
41+
}
42+
};

0 commit comments

Comments
 (0)