[api] reward + thanks

This commit is contained in:
xiaomlove
2022-03-30 15:37:11 +08:00
parent b613a46b8d
commit 3e4a5766c4
38 changed files with 983 additions and 64 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
class Comment extends NexusModel
{
protected $casts = [
@@ -10,6 +12,43 @@ class Comment extends NexusModel
'editdate' => 'datetime',
];
protected $fillable = ['user', 'torrent', 'added', 'text', 'ori_text', 'editedby', 'editdate', 'offer', 'request', 'anonymous'];
const TYPE_TORRENT = 'torrent';
const TYPE_REQUEST = 'request';
const TYPE_OFFER = 'offer';
const TYPE_MAPS = [
self::TYPE_TORRENT => [
'model' => Torrent::class,
'foreign_key' => 'torrent',
'target_name_field' => 'name',
'target_script' => 'details.php?id=%s'
],
self::TYPE_REQUEST => [
'model' => Request::class,
'foreign_key' => 'request',
'target_name_field' => 'request',
'target_script' => 'viewrequests.php?id=%s&req_details=1'
],
self::TYPE_OFFER => [
'model' => Offer::class,
'foreign_key' => 'offer',
'target_name_field' => 'name',
'target_script' => 'offers.php?id=%s&off_details=1'
],
];
public function scopeType(Builder $query, $type)
{
foreach (self::TYPE_MAPS as $key => $value) {
if ($type != $key) {
$query->where($value['foreign_key'], 0);
}
}
return $query;
}
public function related_torrent()
{
return $this->belongsTo(Torrent::class, 'torrent');