73 lines
1.4 KiB
PHP
Executable File
73 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Payment extends Model
|
|
{
|
|
/**
|
|
* Table name of model
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'payments';
|
|
|
|
/**
|
|
* Primary key field name of table
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'payment_id';
|
|
|
|
/**
|
|
* Additional fields from other connected tables
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $appends = [];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [];
|
|
|
|
/**
|
|
* The attributes that should be mutated to dates.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dates = ['is_active'];
|
|
|
|
|
|
public function loyaltyCard()
|
|
{
|
|
return $this->hasOne('App\LoyaltyCard','lcard_id','lcard_id');
|
|
}
|
|
|
|
public function ratings()
|
|
{
|
|
return $this->hasOne('App\Ratings','payment_id','payment_id');
|
|
}
|
|
|
|
public function items()
|
|
{
|
|
return $this->hasMany('App\PaymentsItems','payment_id','payment_id');
|
|
}
|
|
|
|
|
|
public function scopeSort($query, $field, $order)
|
|
{
|
|
switch ($field) {
|
|
case 'card_number':
|
|
$query->leftJoin('loyalty_card', 'loyalty_card.lcard_id', '=','payments.lcard_id');
|
|
$query->orderBy('loyalty_card.card_number', $order);
|
|
break;
|
|
default:
|
|
return $query->orderBy($field, $order);
|
|
}
|
|
}
|
|
}
|