Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
peripherad
/
app
/
Models
:
OrderItems.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; class OrderItems extends Model { use HasFactory; protected $table = 'order_items'; protected $guarded = ['_token']; public function order() { return $this->belongsTo(Order::class); } public function purchaseOrderItems() { return $this->hasMany(PurchaseOrderItem::class, 'order_item_id'); } protected function getTemplateMediaAttribute() { return $this->template ? asset('storage/order/' . $this->template) : ''; } protected function getTemplateUrlAttribute() { return $this->template ? public_path('storage/order/' . $this->template) : ''; } protected function getImageUrlAttribute() { return $this->image ? asset('storage/order/' . $this->image) : ''; } public function product() { return $this->belongsTo(Product::class, 'product_id'); } public function productPrice() { return $this->belongsTo(ProductPrice::class, 'price_id'); } public function itemVariations() { return $this->hasMany(OrderItemVariation::class, 'order_id'); } public function orderItemVariations() { return $this->hasMany(OrderItemVariation::class, 'order_item_id'); } public function orderItemCustomizations() { return $this->hasMany(OrderItemCustomizationData::class, 'order_item_id'); } public function customizationSvg() { return $this->hasMany(OrderItemCustomizationSvg::class, 'order_item_id', 'id'); } protected function getInvoicePathAttribute() { return $this->invoice_number ? public_path('storage/order/' . $this->pdf) : ''; } public static function boot() { parent::boot(); static::deleting(function ($order_item) { if ($order_item->attachment) { if (Storage::disk('order')->exists($order_item->template)) { Storage::disk('order')->delete($order_item->template); } } foreach ($order_item->itemVariations as $variation) { $variation->delete(); } }); } }