mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
ptgen api point support parameter & default user
This commit is contained in:
@@ -17,11 +17,11 @@ class Comment extends NexusModel
|
||||
|
||||
public function create_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user');
|
||||
return $this->belongsTo(User::class, 'user')->withDefault(User::getDefaultUserAttributes());
|
||||
}
|
||||
|
||||
public function update_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'editedby');
|
||||
return $this->belongsTo(User::class, 'editedby')->withDefault(User::getDefaultUserAttributes());
|
||||
}
|
||||
}
|
||||
|
||||
23
app/Models/News.php
Normal file
23
app/Models/News.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class News extends NexusModel
|
||||
{
|
||||
protected $table = 'news';
|
||||
|
||||
protected $fillable = [
|
||||
'userid', 'added', 'title', 'body', 'notify',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'added' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'userid');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -108,7 +108,7 @@ class Torrent extends NexusModel
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner');
|
||||
return $this->belongsTo(User::class, 'owner')->withDefault(User::getDefaultUserAttributes());
|
||||
}
|
||||
|
||||
public function thanks()
|
||||
|
||||
@@ -143,6 +143,31 @@ class User extends Authenticatable
|
||||
'invited_by', 'enabled', 'seed_points',
|
||||
];
|
||||
|
||||
public static function getDefaultUserAttributes(): array
|
||||
{
|
||||
return [
|
||||
'id' => 0,
|
||||
'username' => nexus_trans('user.deleted_username'),
|
||||
'class' => self::CLASS_PEASANT,
|
||||
'email' => '',
|
||||
'status' => self::STATUS_CONFIRMED,
|
||||
'added' => '1970-01-01 08:00:00',
|
||||
'avatar' => '',
|
||||
'uploaded' => 0,
|
||||
'downloaded' => 0,
|
||||
'seedbonus' => 0,
|
||||
'seedtime' => 0,
|
||||
'leechtime' => 0,
|
||||
'enabled' => self::ENABLED_NO,
|
||||
'seed_points' => 0
|
||||
];
|
||||
}
|
||||
|
||||
public static function defaultUser()
|
||||
{
|
||||
return new static(self::getDefaultUserAttributes());
|
||||
}
|
||||
|
||||
public function checkIsNormal(array $fields = ['status', 'enabled'])
|
||||
{
|
||||
if (in_array('status', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) {
|
||||
|
||||
Reference in New Issue
Block a user