Skip to content

Commit

Permalink
Return Without update
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed Jun 18, 2024
1 parent 4ea041d commit 7f2e6d8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion app/Livewire/Alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\View\View;
use Livewire\Component;

class Alerts extends Component
{
public function render(): View
Expand Down
13 changes: 11 additions & 2 deletions app/Livewire/OrderEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
namespace App\Livewire;

use App\Models\Order;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;
use Livewire\Component;

use Illuminate\Support\Facades\Session;
use Livewire\Features\SupportRedirects\Redirector;

class OrderEdit extends Component
{
public Order $order;
Expand All @@ -24,10 +29,14 @@ public function mount(Order $order): void
$this->paymentStatus = $order->payment->status ?? 'pending';
}

public function save(): void
public function save(): RedirectResponse | Redirect | Redirector
{
$this->validate();

if ($this->order->status === $this->status && $this->order->payment->status === $this->paymentStatus) {
return redirect()->route('orders.show', $this->order)->with('warning', 'Order updated successfully.');
}

$this->order->status = $this->status;
$this->order->save();

Expand All @@ -42,7 +51,7 @@ public function save(): void
}
}

session()->flash('message', 'Order updated successfully.');
return redirect()->route('orders.show', $this->order)->with('warning', 'Order updated successfully.');
}

public function render(): View
Expand Down
1 change: 1 addition & 0 deletions app/Models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function getStatusClass(): string
return match ($this->status) {
'pending' => 'bg-gray-500',
'completed' => 'text-green-500 bg-green-500',
'failed' => 'text-red-500 bg-red-500',
default => 'text-gray-500',
};
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/orders/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class="absolute top-0 btn btn-xs btn-circle btn-ghost bg-blue-500 right-0 mt-1 m
<div class="mb-2">
<i class="fas fa-info-circle text-gray-500 mr-2"></i>
<span class="font-bold">Payment Status:</span>
<span class="{{ $order->payment->getStatusClass() }} px-2 py-1 rounded">{{ ucfirst($order->payment->status) }}</span>
<span class="{{ $order->payment->getStatusClass() }} text-white px-2 py-1 rounded">{{ ucfirst($order->payment->status) }}</span>
</div>
@else
<div class="mb-2">
Expand Down

0 comments on commit 7f2e6d8

Please sign in to comment.