belongsTo(Discount::class); } // // public function products(){ // return $this->belongsToMany(Product::class); // } const PENDING = 'PENDING'; const PROCESSING = 'PROCESSING'; const COMPLETED = 'COMPLETED'; const CANCELED = 'CANCELED'; const FAILED = 'FAILED'; protected $casts = [ 'meta' => 'array', ]; protected $guarded = []; public function invoice(){ return $this->belongsTo(Invoice::class,'invoice_id','id'); } public function subInvoices(){ return $this->hasMany(Invoice::class,'invoice_id','id'); } public function customer() { return $this->belongsTo(Customer::class); } public function payments() { return $this->hasMany(Payment::class); } public function successPayments() { return $this->hasMany(Payment::class)->where('status', 'COMPLETED'); } public function payByBankUrl($gateway) { return route('redirect.bank', ['invoice' => $this->id, 'gateway' => $gateway]); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function products() { return $this->belongsToMany(Product::class, 'invoice_product') ->withPivot( 'count', 'price_total', 'data', 'quantity_id' ); } public function isCompleted() { return $this->status == 'COMPLETED' or $this->status == 'PROCESSING'; } public function transport(){ return $this->belongsTo(Transport::class); } public function getRouteKeyName() { return 'hash'; } public function address(){ return $this->belongsTo(Address::class); } public function getAddress(){ if ($this->address_id == null){ return Address::$states[$this->customer->state].','.Address::$cities[$this->customer->state][$this->customer->city].','. $this->customer->address; }else{ return Address::$states[$this->address->state].','.Address::$cities[$this->address->state][$this->address->city].','. Address::where('id',$this->address_id)->first()->address; } } }