Skip to content

Instantly share code, notes, and snippets.

@fatkulnurk
Last active October 15, 2020 14:59
Show Gist options
  • Save fatkulnurk/458abd1d31f1ebdc251296c562440915 to your computer and use it in GitHub Desktop.
Save fatkulnurk/458abd1d31f1ebdc251296c562440915 to your computer and use it in GitHub Desktop.
mutator tidak berfungsi jika menggunakan method upsert
PrepaidProduct::upsert($collection, ['buyer_sku_code'],
[
'product_name',
'category',
'brand',
'type',
'seller_name',
'price',
'buyer_product_status',
'seller_product_status',
'unlimited_stock',
'stock',
'multi',
'start_cut_off',
'end_cut_off',
'desc',
]);
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
class PostpaidProduct extends Model
{
use HasFactory;
use SoftDeletes;
protected $guarded = [];
public function setProductNameAttribute($value)
{
$this->attributes['product_name'] = Str::lower($value);
}
public function setCategoryAttribute($value)
{
$this->attributes['category'] = Str::lower($value);
}
public function setBrandAttribute($value)
{
$this->attributes['brand'] = Str::upper($value);
}
public function setSellerNameAttribute($value)
{
$this->attributes['seller_name'] = Str::upper($value);
}
public function transactions()
{
return $this->hasMany(TransactionPostpaid::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment