mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
[api] reward + thanks
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user