Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nicho's avatar
Level 1

Laravel : how to get $payment_gateway value

Hi i'm currently developing a website. I'm trying to create a feature where, when i create a new booking i can choose the payment method like via xendit or transfer. But when i tried to submit the output of the payment method is still offline payment because of this code {{$row->gatewayObj ? $row->gatewayObj->getDisplayName() : ''}} , and not xendit. How do i fix this??

The Controller :

public function create(Request $request){
            // $this->checkPermission('news_create');
            $allServices = get_bookable_services();
            $whatsAppBookableServices = ["art", "food", "gear", "car", "hotel"];
            $payment_gateway = ["xendit", "offline payment"];//tambahan Nicho
            $row = new BookingOffline();
            $row->fill([
                'status' => 'publish',
            ]);
            $data = [
                // 'categories'        => NewsCategory::get()->toTree(),
                'row'         => $row,
                'breadcrumbs' => [
                    [
                        'name' => __('Report'),
                        'url'  => 'admin/module/report/booking'
                    ],
                    [
                        'name'  => __('Add Booking By WA'),
                        'class' => 'active'
                    ],
                ],
                'bookableServices' => array_keys($allServices),
                'whatsAppBookableServices' => $whatsAppBookableServices,
                'payment_gateway' => $payment_gateway,//tambahan Nicho
            ];
            return view('Report::admin.booking.create', $data);
        }

The gatewayObj :

function get_payment_gateway_obj($payment_gateway)
{

    $gateways = get_payment_gateways();

    if (empty($gateways[$payment_gateway]) or !class_exists($gateways[$payment_gateway])) {
        return false;
    }

    $gatewayObj = new $gateways[$payment_gateway]($payment_gateway);

    return $gatewayObj;
}

The blade.php :

<td>
	{{$row->gatewayObj ? $row->gatewayObj->getDisplayName() : ''}}
</td>
0 likes
2 replies
christian-qode's avatar

Can you share the BookingOffline model? Because now it's not clear how gatewayObj is defined.

Nicho's avatar
Level 1

@cschoenmakers Here's the BookingOffline model :

<?php
namespace Modules\Booking\Models;

class BookingOffline extends Booking
{
    protected $fillable = [
        'vendor_id',
        'customer_id',
        'payment_id',
        'gateway',
        'object_id',
        'object_model',
        'start_date',
        'end_date',
        'total',
        'total_guest',
        'currency',
        'status',
        'deposit',
        'deposit_type',
    ];
}

Please or to participate in this conversation.