Tokens.php
975 Bytes
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Tokens extends Model
{
CONST MAIN = 'main';
CONST GOAL = 'goal';
protected $fillable = ['token', 'login', 'type'];
public function scopeFilter($query, array $filters)
{
$query->when($filters['login'] ?? null, function ($query, $search) {
$query->where('login', 'like', '%'.$search.'%');
})->when($filters['type'] ?? null, function ($query, $type) {
$query->where('type', $type);
})->when($filters['api'] ?? null, function ($query, $api) {
$query->where('api', $api);
});
}
public function limits()
{
return $this->hasMany(Limits::class, 'token', 'id')->orderBy('updated_at', 'DESC');
}
public function campaigns()
{
return $this->hasMany(Campaigns::class, 'token', 'id')->orderBy('updated_at', 'DESC');
}
}