love_php/app/Models/CoinExchange.php

35 lines
719 B
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CoinExchange extends Model
{
protected $fillable = [];
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class);
}
public function scopeKeyword($query)
{
$keyword = request()->keyword;
return $query->whereHas('user', function ($sql) use($keyword) {
$sql->where('nickname', 'like', '%'.$keyword.'%');
});
}
public function scopeStatus($query)
{
return $query->where('status', request()->status);
}
public function goods()
{
return $this->belongsTo(ExchangeGoods::class, 'goods_id', 'id');
}
}