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

LaravelFan's avatar

Error message when submitting PayPal payment

Hi,

I created a user dashboard (for the customer), an admin dashboard (can also sell), and a vendor (can also sell) dashboard. When submitting the PayPal payment (via my sandbox account) I'm getting the error: SQLSTATE[HY000]: General error: 1364 Field 'seller' doesn't have a default value.

Grateful for your guidance on this issue.

This is the PaymentController:

This is the CheckoutController:

This is the checkout.blade.php:

This is the CartController:

This is the cart.blade.php:

This is the order_products migration file:

This is the order_table migration file:

This is the transactions migration file:

This is the OrderProduct model:


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OrderProduct extends Model
{
    use HasFactory;

    // Relationship between OrderProduct and Vendor
    public function vendor()
    {
        return $this->belongsTo(Vendor::class);
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function order()
    {
        return $this->belongsTo(Order::class);
    }
}

This is the Order model:


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasFactory;

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function getCustomerNameAttribute()
    {
        return $this->user ? $this->user->name : 'Unknown'; // Assuming the User model has a 'name' field
    }

    public function transaction()
    {
        return $this->hasOne(Transaction::class);
    }
}

This is the transaction model:


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Transaction extends Model
{
    use HasFactory;

    public function order()
    {
        return $this->belongsTo(Order::class);
    }
}

0 likes
11 replies
LaravelFan's avatar

Is is because the field does not have a default value?

frankhosaka's avatar

I had a trouble when copy code. There was a space before <?php. To fix, i removed the space.

Snapey's avatar

What table has seller?

Why are you not setting a value, when it seems to not be nullable?

Snapey's avatar

Oh, text searching your never ending code, I see in orders table, and not nullable

          $table->text('seller');

but you try to create order without specifying seller;

        $order = new Order();
        $order->invoice_id = rand(1, 999999);  // Generate a random invoice ID
        $order->user_id = Auth::user()->id;
        $order->sub_total = getCartTotal();  // Assuming getCartTotal() returns cart subtotal
        $order->amount = getFinalPayableAmount();  // Assuming this includes tax, shipping, etc.
        $order->currency_name = $setting->currency_name;
        $order->currency_icon = $setting->currency_icon;
        $order->product_qty = \Cart::content()->count();
        $order->payment_method = $paymentMethod;
        $order->payment_status = $paymentStatus;
        $order->order_address = json_encode(Session::get('address'));  // Store the address as JSON
        $order->order_status = 'pending';  // Order initially pending
        $order->save();
LaravelFan's avatar

@Snapey Hi, I made the following changes to the orders migration file:

and made the following changes to the PaymentController:

and now getting: SQLSTATE[HY000]: General error: 1364 Field 'customer' doesn't have a default value

LaravelFan's avatar

@Snapey Hi, I made the following changes to the orders migration file:

and made the following changes to the PaymentController:

and now getting: SQLSTATE[HY000]: General error: 1364 Field 'customer' doesn't have a default value

Hi, I took break and will resume work on it again.

Snapey's avatar

@Mamunsson I assume you are refreshing the database after changing the migration?

LaravelFan's avatar

@Snapey Hi,

Still getting errors.


SQLSTATE[HY000]: General error: 1364 Field 'order_status' doesn't have a default value
SQLSTATE[HY000]: General error: 1364 Field 'payment_status' doesn't have a default value
I'm getting: SQLSTATE[HY000]: General error: 1364 Field 'product' doesn't have a default value

Snapey's avatar

@Mamunsson We've been through this. You cannot create a new record missing some values if you have not made those columns nullable.

Please or to participate in this conversation.