Skip to content

Commit 6ccb534

Browse files
committed
add models and enums
1 parent 6e9cf6d commit 6ccb534

14 files changed

+129
-112
lines changed

app/Enums/AdminRole.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum AdminRole: string
6+
{
7+
case ADMIN = 'ADMIN';
8+
9+
case RESELLER = 'RESELLER';
10+
}

app/Enums/AdminStatus.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum AdminStatus: string
6+
{
7+
case ACTIVE = 'ACTIVE';
8+
9+
case INACTIVE = 'INACTIVE';
10+
}

app/Enums/UserStatus.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum UserStatus: string
6+
{
7+
case NEW = 'NEW';
8+
9+
case EXPIRED = 'EXPIRED';
10+
11+
case ACTIVE = 'ACTIVE';
12+
13+
}

app/Models/Admin.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Enums\AdminRole;
6+
use App\Enums\AdminStatus;
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
class Admin extends Model
10+
{
11+
protected $fillable = ['username', 'password', 'role', 'status'];
12+
13+
protected $casts = [
14+
'status' => AdminStatus::class,
15+
'role' => AdminRole::class,
16+
];
17+
}

app/Models/User.php

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,14 @@
22

33
namespace App\Models;
44

5-
// use Illuminate\Contracts\Auth\MustVerifyEmail;
6-
use Illuminate\Database\Eloquent\Factories\HasFactory;
7-
use Illuminate\Foundation\Auth\User as Authenticatable;
8-
use Illuminate\Notifications\Notifiable;
9-
use Laravel\Sanctum\HasApiTokens;
5+
use App\Enums\UserStatus;
6+
use Illuminate\Database\Eloquent\Model;
107

11-
class User extends Authenticatable
8+
class User extends Model
129
{
13-
use HasApiTokens, HasFactory, Notifiable;
10+
protected $fillable = ['username', 'password', 'email', 'tg_id', 'phone', 'status', 'traffic_limit', 'user_limit', 'start_at_first_connect', 'limit_day'];
1411

15-
/**
16-
* The attributes that are mass assignable.
17-
*
18-
* @var array<int, string>
19-
*/
20-
protected $fillable = [
21-
'name',
22-
'email',
23-
'password',
24-
];
25-
26-
/**
27-
* The attributes that should be hidden for serialization.
28-
*
29-
* @var array<int, string>
30-
*/
31-
protected $hidden = [
32-
'password',
33-
'remember_token',
34-
];
35-
36-
/**
37-
* The attributes that should be cast.
38-
*
39-
* @var array<string, string>
40-
*/
4112
protected $casts = [
42-
'email_verified_at' => 'datetime',
43-
'password' => 'hashed',
13+
'status' => UserStatus::class,
4414
];
4515
}

app/Models/UserTraffic.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class UserTraffic extends Model
8+
{
9+
protected $fillable = ['user_id', 'download', 'upload', 'total'];
10+
}

app/Services/SSHProcess.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
class SSHProcess
6+
{
7+
public function __construct()
8+
{
9+
}
10+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"guzzlehttp/guzzle": "^7.7",
1010
"laravel/framework": "^10.15",
1111
"laravel/sanctum": "^3.2.5",
12-
"laravel/tinker": "^2.8.1"
12+
"laravel/tinker": "^2.8.1",
13+
"symfony/process": "^6.3"
1314
},
1415
"require-dev": {
1516
"fakerphp/faker": "^1.23.0",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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('users', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignIdFor(\App\Models\Admin::class);
17+
$table->string('username')->unique();
18+
$table->string('password');
19+
$table->string('email');
20+
$table->string('tg_id');
21+
$table->char('phone', 11);
22+
$table->string('status');
23+
$table->unsignedTinyInteger('traffic_limit')->default(0);
24+
$table->unsignedTinyInteger('user_limit')->default(0);
25+
$table->boolean('start_at_first_connect')->default(0);
26+
$table->unsignedTinyInteger('limit_day')->default(0);
27+
28+
$table->timestamps();
29+
});
30+
}
31+
32+
/**
33+
* Reverse the migrations.
34+
*/
35+
public function down(): void
36+
{
37+
Schema::dropIfExists('users');
38+
}
39+
};

database/migrations/2014_10_12_000000_create_users_table.php renamed to database/migrations/2023_07_19_190857_create_admins_table.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('users', function (Blueprint $table) {
14+
Schema::create('admins', function (Blueprint $table) {
1515
$table->id();
16-
$table->string('name');
17-
$table->string('email')->unique();
18-
$table->timestamp('email_verified_at')->nullable();
16+
$table->string('username');
1917
$table->string('password');
20-
$table->rememberToken();
18+
$table->string('role');
19+
$table->string('status');
2120
$table->timestamps();
2221
});
2322
}
@@ -27,6 +26,6 @@ public function up(): void
2726
*/
2827
public function down(): void
2928
{
30-
Schema::dropIfExists('users');
29+
Schema::dropIfExists('admins');
3130
}
3231
};

database/migrations/2019_08_19_000000_create_failed_jobs_table.php renamed to database/migrations/2023_07_19_190908_create_user_traffic_table.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('failed_jobs', function (Blueprint $table) {
14+
Schema::create('user_traffic', function (Blueprint $table) {
1515
$table->id();
16-
$table->string('uuid')->unique();
17-
$table->text('connection');
18-
$table->text('queue');
19-
$table->longText('payload');
20-
$table->longText('exception');
21-
$table->timestamp('failed_at')->useCurrent();
16+
$table->foreignIdFor(\App\Models\User::class);
17+
$table->integer('upload')->default(0);
18+
$table->integer('download')->default(0);
19+
$table->integer('total')->default(0);
20+
$table->timestamps();
2221
});
2322
}
2423

@@ -27,6 +26,6 @@ public function up(): void
2726
*/
2827
public function down(): void
2928
{
30-
Schema::dropIfExists('failed_jobs');
29+
Schema::dropIfExists('user_traffic');
3130
}
3231
};

0 commit comments

Comments
 (0)