File: /var/www/ipsremont-demo/app/Models/OrderItems.php
<?php
namespace App\Models;
use App\Traits\Displayed;
use App\Traits\My;
use App\Traits\Sortable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
/**
* @property int $order_id
* @property int $part_id
* @property int $amount
* @property ?string $deleted_at
* @property ?string $created_at
* @property ?string $updated_at
* @property float $price
* @property ?string $part_external_id
*
* @property Part $part
*/
class OrderItems extends BaseModel
{
use SoftDeletes, Sortable, Displayed, My;
protected $table = 'order_items';
protected $fillable = [
'order_id',
'part_id',
'amount',
'price',
'deleted_at',
'part_external_id',
];
public function _save($order_id, $part_id, $amount, $price, $part_external_id)
{
$this->order_id = $order_id;
$this->part_id = $part_id;
$this->amount = $amount;
$this->price = $price;
$this->part_external_id = $part_external_id;
$this->save();
}
public function _update($order_id, $part_id, $amount, $price, $part_external_id)
{
DB::statement("UPDATE `order_items` SET `amount`=$amount,`price`=$price,`part_external_id`=\"$part_external_id\", `deleted_at` = NULL WHERE `order_id`=$order_id AND `part_id`=$part_id");
}
// MARK: - Relations
public function part(): BelongsTo
{
return $this->belongsTo(Part::class)->withTrashed();
}
}