Skip to content

Commit

Permalink
Complete order edit functions and payment status edit for can manage …
Browse files Browse the repository at this point in the history
…users
  • Loading branch information
Raccoon254 committed Jun 18, 2024
1 parent 3b7633a commit da0cfb9
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
35 changes: 34 additions & 1 deletion app/Livewire/OrderEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,44 @@

namespace App\Livewire;

use App\Models\Order;
use Illuminate\View\View;
use Livewire\Component;

class OrderEdit extends Component
{
public function render()
public Order $order;
public $status;
public $paymentStatus;

protected $rules = [
'status' => 'required|string',
'paymentStatus' => 'required|string',
];

public function mount(Order $order): void
{
$this->order = $order;
$this->status = $order->status;
$this->paymentStatus = $order->payment->status ?? 'pending';
}

public function save(): void
{
$this->validate();

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

if ($this->order->payment) {
$this->order->payment->status = $this->paymentStatus;
$this->order->payment->save();
}

session()->flash('message', 'Order updated successfully.');
}

public function render(): View
{
return view('livewire.order-edit');
}
Expand Down
24 changes: 24 additions & 0 deletions database/migrations/2024_06_18_122735_addfailedtopayments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
//
}

/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};
40 changes: 38 additions & 2 deletions resources/views/livewire/order-edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
<div>
{{-- If you look to others for fulfillment, you will never truly be fulfilled. --}}
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
<div class="bg-white shadow overflow-hidden sm:rounded-lg p-6">
<h3 class="text-lg font-medium text-gray-900 mb-4">Edit Order</h3>

@if (session()->has('message'))
<div class="bg-green-500 text-white p-4 mb-4 rounded">
{{ session('message') }}
</div>
@endif

<form wire:submit.prevent="save">
<div class="mb-4">
<label for="status" class="block text-sm font-medium text-gray-700">Order Status</label>
<select id="status" wire:model="status" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option value="in-progress">In Progress</option>
<option value="completed">Completed</option>
<option value="pending">Pending</option>
</select>
@error('status') <span class="text-red-500 text-sm">{{ $message }}</span> @enderror
</div>

<div class="mb-4">
<label for="paymentStatus" class="block text-sm font-medium text-gray-700">Payment Status</label>
<select id="paymentStatus" wire:model="paymentStatus" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option value="pending">Pending</option>
<option value="completed">Completed</option>
<option value="failed">Failed</option>
</select>
@error('paymentStatus') <span class="text-red-500 text-sm">{{ $message }}</span> @enderror
</div>

<div class="flex items-center justify-end mt-4">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Save Changes
</button>
</div>
</form>
</div>
</div>
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Route::get('/orders/{order}', [PagesController::class, 'show_order'])->name('orders.show');
Route::get('/orders/create/new', OrderCreate::class)->name('orders.create');
Route::get('/orders/pay/{orderId}', OrderPayment::class)->name('orders.pay');
Route::view('/orders/{order}/edit', 'static.coming-soon')->name('orders.edit');
Route::get('/orders/{order}/edit', OrderEdit::class)->name('orders.edit');

// TODO: Fix the referral function system
//Route::get('/referrals', Referrals::class)->name('referrals');
Expand Down

0 comments on commit da0cfb9

Please sign in to comment.