diff --git a/app/Http/Controllers/MidtransController.php b/app/Http/Controllers/MidtransController.php index cbe44cc..6818bc4 100644 --- a/app/Http/Controllers/MidtransController.php +++ b/app/Http/Controllers/MidtransController.php @@ -41,12 +41,11 @@ public function paymentgateway(Request $request) $this->initMidtrans(); $snapToken = ''; - $order = Order::create(); - $order->save(); + $orderId = rand(); $params = array( 'transaction_details' => array( - 'order_id' => $order->id, + 'order_id' => $orderId, 'gross_amount' => $totalPrice, ), @@ -79,8 +78,11 @@ public function paymentgateway(Request $request) $snapToken = \Midtrans\Snap::getSnapToken($params); - $order->menu = $input; - $order->total_price = $totalPrice; + $order = Order::create([ + "menu" => json_encode($input), + "total_price" => $totalPrice, + "order_id" => $orderId, + ]); $order->save(); return view('users.kasir.checkout', ['snapToken' => $snapToken]); @@ -96,7 +98,7 @@ public function store(Request $request) $transaction_time = $request->get('transaction_time'); // $signature_key = $request->get('signature_key'); - $order = Order::find($order_id)->firstOrFail(); + $order = Order::where('order_id', $order_id)->firstOrFail(); $order->va_numbers = $va_numbers; $order->transaction_id = $transaction_id; $order->transaction_status = $transaction_status; diff --git a/app/Models/Order.php b/app/Models/Order.php index 684fce4..89ab3d5 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -13,9 +13,10 @@ class Order extends Model public $timestamps = false; protected $primaryKey = 'id'; // Memanggil isi DB Dengan primarykey protected $fillable = [ - 'transaction_id', + 'order_id', 'menu', 'total_price', + 'transaction_id', 'payment_type', 'transaction_time', 'transaction_status', diff --git a/database/migrations/2022_04_22_211254_order.php b/database/migrations/2022_04_22_211254_order.php index 77c4213..7d011c2 100644 --- a/database/migrations/2022_04_22_211254_order.php +++ b/database/migrations/2022_04_22_211254_order.php @@ -16,9 +16,10 @@ public function up() Schema::create('order', function (Blueprint $table) { $table->id(); //item detail + $table->unsignedBigInteger('order_id'); + $table->json('menu'); + $table->unsignedInteger('total_price'); $table->string('transaction_id')->nullable(); - $table->json('menu')->nullable(); - $table->unsignedInteger('total_price')->nullable(); $table->string('payment_type')->nullable(); $table->timestamp('transaction_time')->nullable(); $table->string('transaction_status')->nullable();