For some reason, I cannot create models on this page. It has always worked until today.
What I have done
- I also tested var_dump after and before OrderDetails::create() and both value are the same.
- I messed around with $fillable and it is clear that when column name inside of fillable are not matched database column. Error will be shown.
- I tried all variation of of create method, and still no luck.
I have absolutely no clue what I did wrong here.
additional information: 1. I messed around with phpMailer before I detected this error. One major thing i did is to turn on "allow less secure access" (not exact word) which convert from "ssl" to "tsl."
Below is one of the models I cannot create. I chose to show part of the code that most relevant to my problem.
foreach($_SESSION['user_cart'] as $cart_items){
$productId = $cart_items['product_id'];
//quantity of items in the cart NOT quatity of item availble in the shop
$quantity = $cart_items['quantity'];
$item = Product::where('id', $productId)->first();
//if for some reason, no matching id can be found. skip the item to avoid problems
if(!$item) {continue;}
//totalPrice of selected item * quantity in the cart
$totalPrice = $item->price * $quantity;
$totalPrice = number_format($totalPrice, 2 );
// var_dump($order_id); //?????????????????????????????????????????????????????????????
OrderDetail::create([
'user_id' => _user()->id,
'product_id' => $productId,
'unit_price' => $item->price,
'quantity' => $quantity,
'total' => $totalPrice,
'status' => 'Pending',
'order_no' => $order_id
]);
$item->quantity = $item->quantity - $quantity;
$item->save();
// $test = OrderDetail::where("order_no", $order_id)->get();
// var_dump($test[0]->order_no); //?????????????????????????????????????????????????????
array_push($result['product'], [
'name' => $item->name,
'price' => $item->price,
'total' => $totalPrice,
'quantity' => $
This is my OrderDetail model
namespace SAM\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class OrderDetail extends Model
{
//Illuminate setup6
use SoftDeletes;
public $timestamps = true;
// vars to be inserted to
protected $fillable = ['user_id', 'product_id', 'unit-price', 'quantity', 'total', 'status', 'order_no'];
// protected $fillable = ['user_id', 'product_id', 'unit-price', 'quantity', 'total', 'statu_no'];
protected $dates = ['deleted_at'];
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire