TypeMember.php 934B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Models;
  3. use App\Services\CurrencyFormatService;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Eloquent\Casts\Attribute;
  6. use Illuminate\Database\Eloquent\Factories\HasFactory;
  7. use Illuminate\Database\Eloquent\Model;
  8. class TypeMember extends Model
  9. {
  10. use HasFactory;
  11. protected $fillable = [
  12. 'type',
  13. 'description',
  14. 'price',
  15. 'max',
  16. ];
  17. protected function updatedAt(): Attribute
  18. {
  19. return Attribute::make(
  20. get:fn($value) => Carbon::parse($value)->translatedFormat('l d/m/Y')
  21. );
  22. }
  23. protected function price(): Attribute
  24. {
  25. return Attribute::make(
  26. get:fn($value) => (new CurrencyFormatService)->setRupiahFormat($value, true)
  27. );
  28. }
  29. public function scopeFilter($query, $id)
  30. {
  31. $query->when($id ?? null, function ($query, $id) {
  32. $query->where('id', $id);
  33. });
  34. }
  35. }