Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\DateFormattedModelTrait;
- class Order extends Model
- {
- use HasFactory;
- protected $table = 'orders';
- protected $appends = [
- 'same',
- 'prod_name'
- ];
- protected $fillable = [
- 'id',
- 'date',
- 'auction_numb',
- 'customer_name',
- 'ebay_id',
- 'address',
- 'email',
- 'item',
- 'finish',
- 'prod_status',
- 'return_numb',
- 'payment',
- 'processing_order',
- 'sold_price',
- 'tax',
- 'shipping_cost',
- 'finish_rem',
- 'order_rem',
- 'shipping_rem',
- 'total',
- 'tracking_numb',
- 'sh_adress',
- 'refund',
- 'sh_name',
- 'supplier',
- 'subtotal',
- 'exchange_numb',
- 'position',
- 'phone',
- 'other_item',
- 'other_item_id',
- 'shipped_by',
- 'attention',
- 'qty',
- 'proc_time',
- 'ebayac',
- 'stockwithdraw',
- 'customer_id',
- ];
- public function status() {
- return $this->belongsTo(Status::class, 'prod_status', 'id');
- }
- public function product() {
- return $this->belongsTo(Item::class, 'item', 'id');
- }
- public function scopeToday($query) {
- return $query->where('created_at', '>=',today());
- }
- public function scopeWarning($query) {
- return $query->where('attention', 1);
- }
- public function account() {
- return $this->belongsTo(EbayAccount::class, 'ebayac', 'id');
- }
- public function customer() {
- return $this->belongsTo(Customer::class, 'customer_id', 'id');
- }
- public function getSameAttribute(){
- return $this->sh_adress === $this->address;
- }
- public function getDateAttribute($value): string {
- if (empty($value))
- return '';
- return \Carbon\Carbon::parse($value)->format('m/d/Y');
- }
- public function setDateAttribute($date){
- if (!empty($date)) {
- $this->attributes['date'] = \Carbon\Carbon::parse($date)->format('Y-m-d H:i:s');
- }
- }
- public function getProdNameAttribute(){
- $this->load('product');
- if (is_null($this->item) || $this->item === 0) {
- return $this->other_item;
- }
- if (is_null($this->product)) {
- return null;
- }
- return $this->product->name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment