Skip to content

Commit

Permalink
Status classes in order and payment models
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed May 21, 2024
1 parent 258f725 commit fa5b618
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Livewire/OrderShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function mount(): void

public function sortBy($field): void
{
if ($field === 'payment_status') {
$field = 'status';
}

if ($this->sortField === $field) {
$this->sortAsc = !$this->sortAsc;
} else {
Expand Down
12 changes: 12 additions & 0 deletions app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Order extends Model
{
use HasFactory;

// $table->enum('status', ['pending', 'in-progress', 'completed'])->default('pending');

protected $fillable = [
'user_id', 'title', 'description', 'status', 'total_price',
];
Expand Down Expand Up @@ -40,4 +42,14 @@ public function isPaid(): bool
{
return $this->payment()->exists();
}

public function getStatusClass(): string
{
return match ($this->status) {
'pending' => 'text-yellow-500',
'in-progress' => 'text-blue-500',
'completed' => 'text-green-500',
default => 'text-gray-500',
};
}
}
10 changes: 10 additions & 0 deletions app/Models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Payment extends Model
{
use HasFactory;

// $table->enum('status', ['pending', 'completed'])->default('pending');
protected $fillable = [
'order_id', 'amount', 'payment_method', 'status',
];
Expand All @@ -18,4 +19,13 @@ public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}

public function getStatusClass(): string
{
return match ($this->status) {
'pending' => 'text-yellow-500',
'completed' => 'text-green-500',
default => 'text-gray-500',
};
}
}
2 changes: 2 additions & 0 deletions resources/views/orders/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<i class="fas {{ $this->getSortIcon($field) }}"></i>
</th>
@endforeach
<th class="py-3 text-black/80 text-[14px]">Payment</th>
</tr>
</thead>
<tbody>
Expand All @@ -59,6 +60,7 @@
<td class="px-4 py-2 border-b border-gray-100">{{ $order->description }}</td>
<td class="px-4 py-2 border-b border-gray-100">${{ $order->total_price }}</td>
<td class="px-4 py-2 border-b border-gray-100">{{ $order->status }}</td>
<td class="px-4 py-2 border-b border-gray-100">{{ $order->isPaid() ? $order->payment->status : 'Not Paid' }}</td>
</tr>
@endforeach
</tbody>
Expand Down

0 comments on commit fa5b618

Please sign in to comment.