add tooltip to sidebar buttons remove profile for admin fix mobile menu not opening in home page fix deal image input modal size in mobile view make image scrollable in input modal fix explore page filters are not clickable when recent search is maxed out change UI for the recent searches add seeder for categories improve deal card ui in broker dashboard
70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ReportStatus;
|
|
use App\Enums\ReportType;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property ReportType $type
|
|
* @property ReportStatus $status
|
|
* @property string $description
|
|
* @property int $user_id
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Deal> $deals
|
|
* @property-read int|null $deals_count
|
|
* @property-read \App\Models\User|null $user
|
|
*
|
|
* @method static Builder<static>|Report newModelQuery()
|
|
* @method static Builder<static>|Report newQuery()
|
|
* @method static Builder<static>|Report orderByStatus(array $statusOrder)
|
|
* @method static Builder<static>|Report query()
|
|
* @method static Builder<static>|Report whereCreatedAt($value)
|
|
* @method static Builder<static>|Report whereDescription($value)
|
|
* @method static Builder<static>|Report whereId($value)
|
|
* @method static Builder<static>|Report whereStatus($value)
|
|
* @method static Builder<static>|Report whereType($value)
|
|
* @method static Builder<static>|Report whereUpdatedAt($value)
|
|
* @method static Builder<static>|Report whereUserId($value)
|
|
*
|
|
* @mixin \Eloquent
|
|
*/
|
|
class Report extends Model
|
|
{
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function deals(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Deal::class);
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'type' => ReportType::class,
|
|
'status' => ReportStatus::class,
|
|
];
|
|
}
|
|
|
|
#[Scope]
|
|
public function orderByStatus(Builder $query, array $statusOrder): Builder
|
|
{
|
|
$values = array_map(fn ($enum) => $enum->value, $statusOrder);
|
|
|
|
// Create placeholders for each value: FIELD(status, ?, ?, ?)
|
|
$placeholders = implode(',', array_fill(0, count($values), '?'));
|
|
|
|
return $query->orderByRaw("FIELD(status, $placeholders)", $values);
|
|
}
|
|
}
|