38 lines
784 B
PHP
38 lines
784 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Laravel\Scout\Searchable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class Trading extends Model
|
|
{
|
|
use \Backpack\CRUD\app\Models\Traits\CrudTrait;
|
|
use HasFactory;
|
|
|
|
protected $guarded = ['id'];
|
|
protected $casts = [
|
|
'price' => 'float',
|
|
'total' => 'float',
|
|
'amount' => 'float',
|
|
];
|
|
protected $appends = ['total'];
|
|
protected $with = ['category'];
|
|
|
|
public function scopeLines($query)
|
|
{
|
|
return $query->where('is_line', true);
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
|
|
public function getTotalAttribute()
|
|
{
|
|
return round($this->price * $this->amount, 2);
|
|
}
|
|
}
|