✨ 完善模型
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
|
||||
/**
|
||||
* @method static static Local()
|
||||
*/
|
||||
final class StrategyKey extends Enum
|
||||
{
|
||||
/** @var int 本地 */
|
||||
const Local = 1;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
|
||||
/**
|
||||
* @method static static Normal()
|
||||
* @method static static Frozen()
|
||||
*/
|
||||
final class UserStatus extends Enum
|
||||
{
|
||||
/** @var int 正常 */
|
||||
const Normal = 1;
|
||||
|
||||
/** @var int 冻结 */
|
||||
const Frozen = 0;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Enums\UserStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
@@ -39,10 +40,14 @@ class RegisteredUserController extends Controller
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// TODO 获取默认组
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
'registered_ip' => $request->ip(),
|
||||
'status' => UserStatus::Normal,
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $name
|
||||
* @property string $intro
|
||||
* @property int $image_num
|
||||
* @property-read User $user
|
||||
* @property-read Image[] $images
|
||||
*/
|
||||
class Album extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'intro',
|
||||
'image_num'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'user_id',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'intro' => '',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function images(): HasMany
|
||||
{
|
||||
return $this->hasMany(Image::class, 'album_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property string $name
|
||||
* @property mixed $value
|
||||
*/
|
||||
class Config extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property boolean $is_default
|
||||
* @property Collection $configs
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $created_at
|
||||
* @property-read User[] $users
|
||||
* @property-read Strategy[] $strategies
|
||||
*/
|
||||
class Group extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'is_default',
|
||||
'configs',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_default' => 'bool',
|
||||
'configs' => 'collection',
|
||||
];
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function strategies(): HasMany
|
||||
{
|
||||
return $this->hasMany(Strategy::class, 'group_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $album_id
|
||||
* @property int $strategy_id
|
||||
* @property string $path
|
||||
* @property string $name
|
||||
* @property string $origin_name
|
||||
* @property string $alias_name
|
||||
* @property float $size
|
||||
* @property string $mimetype
|
||||
* @property string $md5
|
||||
* @property string $sha1
|
||||
* @property boolean $is_unhealthy
|
||||
* @property string $uploaded_ip
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $created_at
|
||||
* @property-read User $user
|
||||
* @property-read Album $album
|
||||
* @property-read Strategy $strategy
|
||||
*/
|
||||
class Image extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'album_id',
|
||||
'strategy_id',
|
||||
'path',
|
||||
'name',
|
||||
'origin_name',
|
||||
'alias_name',
|
||||
'size',
|
||||
'mimetype',
|
||||
'md5',
|
||||
'sha1',
|
||||
'is_unhealthy',
|
||||
'uploaded_ip',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'user_id',
|
||||
'album_id',
|
||||
'strategy_id',
|
||||
'uploaded_ip',
|
||||
'is_unhealthy',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'size' => 'float',
|
||||
'is_unhealthy' => 'bool',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function album(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Album::class, 'album_id', 'id');
|
||||
}
|
||||
|
||||
public function strategy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Strategy::class, 'strategy_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $group_id
|
||||
* @property string $key
|
||||
* @property string $name
|
||||
* @property string $intro
|
||||
* @property Collection $configs
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $created_at
|
||||
* @property-read Group $group
|
||||
* @property-read Image[] $images
|
||||
*/
|
||||
class Strategy extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'group_id',
|
||||
'key',
|
||||
'name',
|
||||
'intro',
|
||||
'configs',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'group_id',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'intro' => '',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'configs' => 'collection',
|
||||
];
|
||||
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Group::class, 'group_id', 'id');
|
||||
}
|
||||
|
||||
public function images(): HasMany
|
||||
{
|
||||
return $this->hasMany(Image::class, 'strategy_id', 'id');
|
||||
}
|
||||
}
|
||||
+55
-1
@@ -2,12 +2,36 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $group_id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property string $remember_token
|
||||
* @property boolean $is_adminer
|
||||
* @property float $capacity
|
||||
* @property Collection $configs
|
||||
* @property int $image_num
|
||||
* @property int $album_num
|
||||
* @property string $registered_ip
|
||||
* @property string $status
|
||||
* @property Carbon $email_verified_at
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $created_at
|
||||
* @property-read Group $group
|
||||
* @property-read Album[] $albums
|
||||
* @property-read Image[] $images
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
@@ -21,6 +45,8 @@ class User extends Authenticatable
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'configs',
|
||||
'registered_ip',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -44,6 +70,34 @@ class User extends Authenticatable
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'capacity' => 'float',
|
||||
'is_adminer' => 'bool',
|
||||
'configs' => 'collection',
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function (self $user) {
|
||||
$user->configs = collect([
|
||||
'default_album' => 0,
|
||||
'default_strategy' => 0,
|
||||
])->merge($user->configs ?: []);
|
||||
});
|
||||
}
|
||||
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Group::class, 'group_id', 'id');
|
||||
}
|
||||
|
||||
public function album(): HasMany
|
||||
{
|
||||
return $this->hasMany(Album::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function images(): HasMany
|
||||
{
|
||||
return $this->hasMany(Image::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^7.3|^8.0",
|
||||
"bensampo/laravel-enum": "^4.1",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"laravel/breeze": "^1.5",
|
||||
|
||||
Generated
+217
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "83073760f6b879d24c8174081d99c814",
|
||||
"content-hash": "e48f64e43c40bcd6fa323a8af28df3c2",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
@@ -68,6 +68,95 @@
|
||||
},
|
||||
"time": "2021-03-11T06:42:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "bensampo/laravel-enum",
|
||||
"version": "v4.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/BenSampo/laravel-enum.git",
|
||||
"reference": "27e5a82e1830495e6b88bab6d38389b730c05e39"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/BenSampo/laravel-enum/zipball/27e5a82e1830495e6b88bab6d38389b730c05e39",
|
||||
"reference": "27e5a82e1830495e6b88bab6d38389b730c05e39",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"hanneskod/classtools": "^1.2",
|
||||
"illuminate/contracts": "^8.0",
|
||||
"illuminate/support": "^8.0",
|
||||
"laminas/laminas-code": "^3.4|^4.0",
|
||||
"nikic/php-parser": "^4.10",
|
||||
"php": "^7.3|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/dbal": "^2.9|^3.0",
|
||||
"mockery/mockery": "^1.4",
|
||||
"orchestra/testbench": "^6.2",
|
||||
"phpstan/phpstan": "^0.12.59",
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"BenSampo\\Enum\\EnumServiceProvider"
|
||||
]
|
||||
},
|
||||
"phpstan": {
|
||||
"includes": [
|
||||
"extension.neon"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"BenSampo\\Enum\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ben Sampson",
|
||||
"homepage": "https://sampo.co.uk",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Simple, extensible and powerful enumeration implementation for Laravel.",
|
||||
"homepage": "https://github.com/bensampo/laravel-enum",
|
||||
"keywords": [
|
||||
"bensampo",
|
||||
"enum",
|
||||
"laravel",
|
||||
"package",
|
||||
"validation"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/BenSampo/laravel-enum/issues",
|
||||
"source": "https://github.com/BenSampo/laravel-enum/tree/v4.1.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/bensampo",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2021-11-16T10:29:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "brick/math",
|
||||
"version": "0.9.3",
|
||||
@@ -1031,6 +1120,133 @@
|
||||
],
|
||||
"time": "2021-10-06T17:43:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "hanneskod/classtools",
|
||||
"version": "1.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/hanneskod/classtools.git",
|
||||
"reference": "d365ddac0e602027c0471ea292f4ba2afcb49394"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/hanneskod/classtools/zipball/d365ddac0e602027c0471ea292f4ba2afcb49394",
|
||||
"reference": "d365ddac0e602027c0471ea292f4ba2afcb49394",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"nikic/php-parser": "^4",
|
||||
"php": ">=7.1",
|
||||
"symfony/finder": "^4|^5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"hanneskod\\classtools\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"WTFPL"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Hannes Forsgård",
|
||||
"email": "hannes.forsgard@fripost.org"
|
||||
}
|
||||
],
|
||||
"description": "Find, extract and process classes from file system",
|
||||
"homepage": "https://github.com/hanneskod/classtools",
|
||||
"keywords": [
|
||||
"class finder",
|
||||
"code generator",
|
||||
"metaprogramming",
|
||||
"minimizer"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/hanneskod/classtools/issues",
|
||||
"source": "https://github.com/hanneskod/classtools/tree/1.0"
|
||||
},
|
||||
"time": "2020-03-05T20:41:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laminas/laminas-code",
|
||||
"version": "4.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laminas/laminas-code.git",
|
||||
"reference": "c99ef8e5629c33bfaa3a8f1df773e916af564cd6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laminas/laminas-code/zipball/c99ef8e5629c33bfaa3a8f1df773e916af564cd6",
|
||||
"reference": "c99ef8e5629c33bfaa3a8f1df773e916af564cd6",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.4, <8.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/annotations": "^1.13.2",
|
||||
"ext-phar": "*",
|
||||
"laminas/laminas-coding-standard": "^2.3.0",
|
||||
"laminas/laminas-stdlib": "^3.6.1",
|
||||
"phpunit/phpunit": "^9.5.10",
|
||||
"psalm/plugin-phpunit": "^0.16.1",
|
||||
"vimeo/psalm": "^4.13.1"
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/annotations": "Doctrine\\Common\\Annotations >=1.0 for annotation features",
|
||||
"laminas/laminas-stdlib": "Laminas\\Stdlib component"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laminas\\Code\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"polyfill/ReflectionEnumPolyfill.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"description": "Extensions to the PHP Reflection API, static code scanning, and code generation",
|
||||
"homepage": "https://laminas.dev",
|
||||
"keywords": [
|
||||
"code",
|
||||
"laminas",
|
||||
"laminasframework"
|
||||
],
|
||||
"support": {
|
||||
"chat": "https://laminas.dev/chat",
|
||||
"docs": "https://docs.laminas.dev/laminas-code/",
|
||||
"forum": "https://discourse.laminas.dev",
|
||||
"issues": "https://github.com/laminas/laminas-code/issues",
|
||||
"rss": "https://github.com/laminas/laminas-code/releases.atom",
|
||||
"source": "https://github.com/laminas/laminas-code"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://funding.communitybridge.org/projects/laminas-project",
|
||||
"type": "community_bridge"
|
||||
}
|
||||
],
|
||||
"time": "2021-12-07T06:00:32+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel-lang/lang",
|
||||
"version": "10.1.11",
|
||||
|
||||
@@ -30,7 +30,7 @@ class CreateUsersTable extends Migration
|
||||
$table->unsignedBigInteger('image_num')->default(0)->comment('图片数量');
|
||||
$table->unsignedBigInteger('album_num')->default(0)->comment('相册数量');
|
||||
$table->string('registered_ip')->default('')->comment('注册IP');
|
||||
$table->enum('status', ['normal', 'frozen'])->default('normal');
|
||||
$table->unsignedTinyInteger('status')->default(1)->comment('状态');
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ class CreateStrategiesTable extends Migration
|
||||
|
||||
$table->id();
|
||||
$table->foreignId('group_id')->comment('角色组')->constrained('groups')->onDelete('cascade');
|
||||
$table->enum('key', ['local'])->default('local');
|
||||
$table->unsignedTinyInteger('key');
|
||||
$table->string('name', 64)->comment('策略名称');
|
||||
$table->string('intro', 255)->default('')->comment('简介');
|
||||
$table->json('configs')->comment('策略配置');
|
||||
|
||||
Reference in New Issue
Block a user