new CartItem (['amount' => $amount])

iqweqwkeqwewqeqweqweqwe發表於2020-04-28
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CartItem extends Model
{
    protected $fillable = ['amount'];
    public $timestamps = false;

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

    public function productSku()
    {
        return $this->belongsTo(ProductSku::class);
    }
}

use App\Models\CartItem;
$cart = new CartItem([‘amount’ => $amount]);//為什麼可以這樣用,直接new 一下,amount的值就傳進去了?

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章